سؤال

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.
     */
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top