简体   繁体   中英

How are combination keypresses calculated in JavaScript CKEditor?

I've written a listener for key presses using CKEditor and jQuery

ckeditor.on('key', keyListener);

function keyListener(ev){
    console.log(ev.data.keyCode);
}

Now if I press a I get 65 , if I press Ctrl I get 1114129 and their combination yields 1114202 .

Can someone please explain the magic behind how this is calculated, please?

From the source code it's calculated in the following way: ref: http://docs.ckeditor.com/source/event.html

/**
     * Gets a number represeting the combination of the keys pressed during the
     * event. It is the sum with the current key code and the {@link CKEDITOR#CTRL},
     * {@link CKEDITOR#SHIFT} and {@link CKEDITOR#ALT} constants.
     *
     *      alert( event.getKeystroke() == 65 );                                    // 'a' key
     *      alert( event.getKeystroke() == CKEDITOR.CTRL + 65 );                    // CTRL + 'a' key
     *      alert( event.getKeystroke() == CKEDITOR.CTRL + CKEDITOR.SHIFT + 65 );   // CTRL + SHIFT + 'a' key
     *
     * @returns {Number} The number representing the keys combination.
     */

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM