3 ms·
On chrome, 'ctrl-[' triggers a key event with .which, .keyCode, and .charCode all set to 27. 27 is DOM_VK_ESCAPE [1]. On firefox, 'esc' sets .keyCode to 27 [2].
by uvdiv 14y ago
On chrome, 'ctrl-[' triggers a key event with .which, .keyCode, and .charCode all set to 27. 27 is DOM_VK_ESCAPE [1]. On firefox, 'esc' sets .keyCode to 27 [2]. Firefox's 'ctrl-[' sets .which and .charCode to 91 (codepoint for '['), but .keyCode to 0. On both firefox and chrome, plain '[' sets .charCode to 91, as does firefox's 'alt-['. But not 'ctrl-[' on chrome.
(which,keyCode,charCode)
chrome firefox
[ 91 91 91 91 0 91
alt-[ ? 91 0 91
ctrl-[ 27 27 27 91 0 91
esc ? 0 27 0
It's one example out of many, but how do you distinguish such cases, short of enumerating the behavior of every browser (and I guess keyboard layout too)?
[1] https://developer.mozilla.org/en/DOM/KeyboardEvent#Virtual_key_codes https://developer.mozilla.org/en/DOM/KeyboardEvent#Virtual_k...
[2] I don't know what chrome does, I couldn't convince it to capture an 'esc' or 'alt-['.
- kalleboo 14y agoAnd on my Swedish keyboard you type "[" with alt-8, so when I press ctrl-alt-8, all bets are off.
- natedsaint 14y agoThanks for this, I noticed the same thing on chrome with other tools like codepen.io and wasn't able to figure out why it was happening.