如何在JavaScript CKEditor中计算组合按键?

时间:2014-03-13 08:29:51

标签: javascript jquery ckeditor keypress keycode

我使用CKEditor和jQuery编写了一个关键按键的监听器

ckeditor.on('key', keyListener);

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

现在,如果我按a,我会65,如果我按Ctrl,我会1114129,他们的组合会产生1114202

有人可以解释一下计算方法背后的魔力吗?

1 个答案:

答案 0 :(得分:1)

从源代码中按以下方式计算: 参考: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.
     */