2014-03-13 53 views
0

我寫了一個偵聽器使用的CKEditor和jQuery在JavaScript CKEditor中如何計算組合按鍵?

ckeditor.on('key', keyListener); 

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

現在的按鍵,如果我按a我得到65,如果我按Ctrl我得到1114129及其組合產生1114202

有人可以請解釋這背後的魔法嗎?

回答

1

從它的計算方法如下代碼: 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. 
    */ 
+0

謝謝您的回答! – Dropout