-
Notifications
You must be signed in to change notification settings - Fork 0
KeyEvents
Here are some notes about noVNC keyboard event handling.
The following table is a list of keyboard events across different browsers in the order that they happen for different keyboard input/actions. This assumes that in keyDown, special keys have their default action stopped and are prevented from bubbling (this stops the keyPress event in Webkit and IE9).
Input Action |
Webkit (Chrome/Safari) | Firefox 4.0 (and 3.6) | Opera 11 | IE 9 |
's' |
D: 83 / 0 / 83 P: 115 / 115 / 115 U: 83 / 0 / 83 |
D: 83 / 0 / 83 P: 0 / 115 / 115 U: 83 / 0 / 83 |
D: 83 / u / 83 P: 115 / u / 115 U: 83 / u / 83 |
D: 83 / u / u P: 115 / u / u U: 83 / u / u |
F4 |
D: 115 / 0 / 115 P: --------------- U: 115 / 0 / 115 |
D: 115 / 0 / 115 P: 115 / 0 / 0 U: 115 / 0 / 115 |
D: 115 / u / 115 P: 115 / u / 0 U: 115 / u / 115 |
D: 115 / u / u P: --------------- U: 115 / u / u |
Ctrl-C |
D: 17 / 0 / 17 D: 67 / 0 / 67 P: --------------- U: 67 / 0 / 67 U: 17 / 0 / 17 |
D: 17 / 0 / 17 D: 67 / 0 / 67 P: 0 / 99 / 99 U: 67 / 0 / 67 U: 17 / 0 / 17 |
D: 17 / u / 17 D: 67 / u / 67 P: 99 / u / 99 U: 67 / u / 67 U: 17 / u / 17 |
D: 17 / u / u D: 67 / u / 67 P: --------------- U: 67 / u / 67 U: 17 / u / 17 |
Legend:
D: = keyDown event
P: = keyPress event
U: = keyUp event
k/c/w = keyCode / charCode / which
u = undefined value
Using the noVNC tests/input.html page, type the following key combinations:
's'
F4
Ctrl-C
'-'
Insert
This should result in the following in the messages box (less the blank lines). The values in parens can vary between browsers, but the keysym values should be identical.
1: keyPress down keysym: 115 (key: 0, char: 115, which: 115)
2: keyPress up keysym: 115 (key: 83, char: 0, which: 83)
3: keyPress down keysym: 65473 (key: 115, char: 0, which: 115)
4: keyPress up keysym: 65473 (key: 115, char: 0, which: 115)
5: keyPress down keysym: 65507 (key: 17, char: 0, which: 17)
6: keyPress down keysym: 99 (key: 67, char: 0, which: 67)
7: keyPress up keysym: 99 (key: 67, char: 0, which: 67)
8: keyPress up keysym: 65507 (key: 17, char: 0, which: 17)
9: keyPress down keysym: 45 (key: 0, char: 45, which: 45)
10: keyPress up keysym: 45 (key: 109, char: 0, which: 109)
11: keyPress down keysym: 65379 (key: 45, char: 0, which: 45)
12: keyPress up keysym: 65379 (key: 45, char: 0, which: 45)
In the same test page, type the following key combinations. There should not be any default browser reponse to them. For example, Ctrl-W should not close the tab and Alt-F should not activate a browser menu.
Ctrl-W
Alt-F
The resulting messages output should look like this:
13: keyPress down keysym: 65507 (key: 17, char: 0, which: 17)
14: keyPress down keysym: 119 (key: 87, char: 0, which: 87)
15: keyPress up keysym: 119 (key: 87, char: 0, which: 87)
16: keyPress up keysym: 65507 (key: 17, char: 0, which: 17)
17: keyPress down keysym: 65513 (key: 18, char: 0, which: 18)
18: keyPress down keysym: 102 (key: 70, char: 0, which: 70)
19: keyPress up keysym: 102 (key: 70, char: 0, which: 70)
20: keyPress up keysym: 65513 (key: 18, char: 0, which: 18)
All Ctrl key combinations should be properly suppressed across all browsers and operating systems. In Opera, the Alt key combinations cannot be properly suppressed. In Windows, all browsers seem to have trouble properly suppressing Alt key combinations. Chrome is best with a beep sound, other browsers open a Window.
Modifier keys such as SHIFT, CTRL, ALT and ALTGR are special keys to modify characters associated with normal keys. Modifier keys also generates key events themselves, but some of them are not what is expected depending on browsers.
ALT keyup events may be lost. When you hit the ALT and a keys, you will lose the ALT keyup event.
keydown keyCode=18 which=18 charCode=0
keydown keyCode=65 (A) which=65 (A) charCode=0
keypress keyCode=0 which=97 (a) charCode=97 (a)
keyup keyCode=65 (A) which=65 (A) charCode=0
This problem won't happen with FireFox 16 for Linux.
keydown keyCode=18 which=18 charCode=0
keydown keyCode=65 (A) which=65 (A) charCode=0
keypress keyCode=0 which=97 (a) charCode=97 (a)
keyup keyCode=65 (A) which=65 (A) charCode=0
keyup keyCode=18 which=18 charCode=0
When you hit the CTRL key, you will get a keyup event for the key whose ctrlKey attribute is "true", which is expected to be "false." This doesn't happen on FireFox 14 or 16.
keydown keyCode=17 which=17 charCode=0
shiftKey=false ctrlKey=true altKey=false metaKey=false
keyup keyCode=17 which=17 charCode=0
shiftKey=false ctrlKey=true altKey=false metaKey=false
FireFox 16 works fine like:
keydown keyCode=17 which=17 charCode=0
shiftKey=false ctrlKey=true altKey=false metaKey=false
keyup keyCode=17 which=17 charCode=0
shiftKey=false ctrlKey=false altKey=false metaKey=false
Most web browsers emulate ALTGR key to generate CTRL and ALT key events instead of generating a native ALTGR key event, which only Firefox 15 or later for linux supports at the day of Nov 6th 2012.
When you hit the ALTGR and q keys to input @ on a German keyboard, you will lose the keyup event for the ALT key, whose keyCode is 18.
keydown keyCode=17 which=17 charCode=0
keydown keyCode=18 which=18 charCode=0
keydown keyCode=81 (Q) which=81 (Q) charCode=0
keypress keyCode=0 which=64 (@) charCode=64 (@)
keyup keyCode=81 (Q) which=81 (Q) charCode=0
keyup keyCode=17 which=17 charCode=0
Even IE9 sometimes loses ALT keyup events. When you hit the ALT and b keys, and you will get:
keydown keyCode=18 which=undefined charCode=undefined
keydown keyCode=66 (B) which=undefined charCode=undefined
keyup keyCode=66 (B) which=undefined charCode=undefined
Hitting an ALTGR key generates CTRL and ALT key events. The point is the keyup event for CTRL is fired before that for ALT.
keydown keyCode=17 which=undefined charCode=undefined
keydown keyCode=18 which=undefined charCode=undefined
keyup keyCode=17 which=undefined charCode=undefined
keyup keyCode=18 which=undefined charCode=undefined
When you hit the ALTGR and q keys to generate CTRL and ALT key events:
-
you will lose the keyup event for CTRL
-
you will get two keypress events and the second one is what you need
keydown keyCode=17 which=17 charCode=undefined keydown keyCode=18 which=18 charCode=undefined keydown keyCode=81 (Q) which=81 (Q) charCode=undefined keypress keyCode=113 (q) which=113 (q) charCode=undefined keypress keyCode=64 (@) which=64 (@) charCode=undefined keyup keyCode=81 (Q) which=81 (Q) charCode=undefined keyup keyCode=18 which=18 charCode=undefined
The ALRGR key generates broken events. When you hit the ALTGR and q keys, the following events will be generated. This version seems to have a bug.
keydown keyCode=0 which=0 charCode=0
keydown keyCode=229 which=229 charCode=0
keyup keyCode=229 which=229 charCode=0
keyup keyCode=0 which=0 charCode=0
The ALRGR key works as a modifier but it won't generate its own keyCode. When you hit the ALTGR and q keys, the following events will be generated. The keyCode of the q key is also twisted.
keydown keyCode=0 which=0 charCode=0
keydown keyCode=50 (2) which=50 (2) charCode=0
keypress keyCode=64 (@) which=64 (@) charCode=64 (@)
keyup keyCode=50 (2) which=50 (2) charCode=0
keyup keyCode=0 which=0 charCode=0
This version works fine with the ALTGR key. When you hit the ALTGR and q keys, the following events will be generated.
keydown keyCode=17 which=17 charCode=0
keydown keyCode=18 which=18 charCode=0
keydown keyCode=81 (Q) which=81 (Q) charCode=0
keypress keyCode=64 (@) which=64 (@) charCode=64 (@)
keyup keyCode=81 (Q) which=81 (Q) charCode=0
keyup keyCode=18 which=18 charCode=0
keyup keyCode=17 which=17 charCode=0
The ALRGR key works as a modifier but it won't generate its own keyCode. When you hit the ALTGR and q keys, the following events will be generated. This behavior is similar to that of Chrome.
keydown keyCode=0 which=0 charCode=0
keydown keyCode=81 (Q) which=81 (Q) charCode=0
keypress keyCode=64 (@) which=64 (@) charCode=64 (@)
keyup keyCode=81 (Q) which=81 (Q) charCode=0
keyup keyCode=0 which=0 charCode=0
Holding a key pressed will generate the same key event repeatedly. All browsers except Opera repeat the keydown and keypress events while Opera only repeats the keypress event.
keydown keyCode=65 (A) which=65 (A) charCode=0
keypress keyCode=0 which=97 (a) charCode=97 (a)
keydown keyCode=65 (A) which=65 (A) charCode=0
keypress keyCode=0 which=97 (a) charCode=97 (a)
keydown keyCode=65 (A) which=65 (A) charCode=0
keypress keyCode=0 which=97 (a) charCode=97 (a)
keyup keyCode=65 (A) which=65 (A) charCode=0
keydown keyCode=65 (A) which=undefined charCode=undefined
keypress keyCode=97 (a) which=undefined charCode=undefined
keydown keyCode=65 (A) which=undefined charCode=undefined
keypress keyCode=97 (a) which=undefined charCode=undefined
keydown keyCode=65 (A) which=undefined charCode=undefined
keypress keyCode=97 (a) which=undefined charCode=undefined
keyup keyCode=65 (A) which=undefined charCode=undefined
keydown keyCode=65 (A) which=65 (A) charCode=0
keypress keyCode=97 (a) which=97 (a) charCode=97 (a)
keydown keyCode=65 (A) which=65 (A) charCode=0
keypress keyCode=97 (a) which=97 (a) charCode=97 (a)
keydown keyCode=65 (A) which=65 (A) charCode=0
keypress keyCode=97 (a) which=97 (a) charCode=97 (a)
keyup keyCode=65 (A) which=65 (A) charCode=0
keydown keyCode=65 (A) which=65 (A) charCode=undefined
keypress keyCode=97 (a) which=97 (a) charCode=undefined
keypress keyCode=97 (a) which=97 (a) charCode=undefined
keypress keyCode=97 (a) which=97 (a) charCode=undefined
keypress keyCode=97 (a) which=97 (a) charCode=undefined
keypress keyCode=97 (a) which=97 (a) charCode=undefined
keyup keyCode=65 (A) which=65 (A) charCode=undefined
When you hit the ^ key twice, your browser won't generate a keypress event at the first try, and two keypress events will be fired on the second try. Hitting " ~ " and " ` " also show the same behavior. The keyCodes are various depending on browsers. This will also happens with other European keyboards.
keydown keyCode=160
keyup keyCode=160
keydown keyCode=160
keypress charCode=94 (^)
keypress charCode=94 (^)
keyup keyCode=160
keydown keyCode=220
keyup keyCode=220
keydown keyCode=220
keypress keyCode=94 (^)
keypress keyCode=94 (^)
keyup keyCode=220
keydown keyCode=220
keyup keyCode=220
keydown keyCode=220
keypress charCode=94 (^)
keypress charCode=94 (^)
keyup keyCode=220
keydown keyCode=54 (6)
keyup keyCode=54 (6)
keydown keyCode=54 (6)
keypress keyCode=94 (^)
keypress keyCode=94 (^)
keyup keyCode=54 (6)
If you want to input characters with diacritics such as ê,õ through browsers with European keyboards, you need to use the space key. You have to type the ' ^ ' key, the space key, and then the ' e ' key if you want to input ê.
keydown keyCode=160 which=160 charCode=0
keyup keyCode=160 which=160 charCode=0
keydown keyCode=32 ( ) which=32 ( ) charCode=0
keypress keyCode=0 which=94 (^) charCode=94 (^)
keyup keyCode=32 ( ) which=32 ( ) charCode=0
keydown keyCode=69 (E) which=69 (E) charCode=0
keypress keyCode=0 which=101 (e) charCode=101 (e)
keyup keyCode=69 (E) which=69 (E) charCode=0
When you are a Linux user, it is more serious.
When you hit the ' ^ ' key twice, the following events will be generated. There is no keypress events for ' ^ '. This version seems to have a serious bug.
keyup keyCode=0 which=0 charCode=0
keydown keyCode=0 which=0 charCode=0
keyup keyCode=0 which=0 charCode=0
Hitting the ' ^ ' key followed by the space key won't fire proper key events either.
keyup keyCode=0 which=0 charCode=0
keydown keyCode=32 ( ) which=32 ( ) charCode=0
keyup keyCode=32 ( ) which=32 ( ) charCode=0
When you hit the ' ^ ' key twice, you can get a keyCode for ' ^ '. Chrome 23.0 for Linux also shows the same behavior.
keydown keyCode=192 which=192 charCode=0
keypress keyCode=94 (^) which=94 (^) charCode=94 (^)
keyup keyCode=192 which=192 charCode=0
When you hit the ' ^ ' key twice, you will get the following events. It is completely broken.
keyup keyCode=192 which=192 charCode=0
keydown keyCode=231 which=231 charCode=0
keypress keyCode=94 (^) which=94 (^) charCode=94 (^)
keyup keyCode=192 which=192 charCode=0
It is popular to use an IME to input non-alphabetical characters. It intercepts all key events to leave the events broken. If the IME gets activated, you may get 229 as a keyCode on any key strokes and there will be no keypress events.
When you hit the ' a ' key with the IME active, you may get these events:
keydown keyCode=229 which=undefined charCode=undefined
keyup keyCode=65 (A) which=undefined charCode=undefined