From c3f6052435249033a36b807bc95e03942aba664f Mon Sep 17 00:00:00 2001 From: Jesper Dam Date: Wed, 12 Mar 2014 10:08:14 +0100 Subject: [PATCH 1/2] Better key identifiers Previously we identified keys in keyboard events by the 'key' property if it was set, and 'keyCode' otherwise. This turns out to be problematic as Firefox no longer leaves 'key' undefined (so we fall back to using 'keyCode'), but instead sets 'key' to 'MozPrintableKey' for all printable keys. This meant that when (printable) keys are released, we can't match it against the corresponding keydown event, and instead just send a keyup event for the last keydown received. Now, if both 'key' and 'keyCode' are set, use the concatenation of both. Otherwise prefer 'keyCode', as that is at least unique for every key. This should let us release the right keys on keyup events. --- include/keyboard.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/keyboard.js b/include/keyboard.js index f21f9767..3fde55bb 100644 --- a/include/keyboard.js +++ b/include/keyboard.js @@ -152,11 +152,14 @@ var kbdUtil = (function() { // Get a key ID from a keyboard event // May be a string or an integer depending on the available properties function getKey(evt){ - if (evt.key) { - return evt.key; + if ('keyCode' in evt && 'key' in evt) { + return evt.key + ':' + evt.keyCode; + } + else if ('keyCode' in evt) { + return evt.keyCode; } else { - return evt.keyCode; + return evt.key; } } From 230784066c7950316b8267a508406eb571e0ff79 Mon Sep 17 00:00:00 2001 From: Jesper Dam Date: Wed, 12 Mar 2014 11:11:52 +0100 Subject: [PATCH 2/2] Better browser OS detection. Apparently Firefox on Linux changed the value of navigator.appVersion, causing our OS detection (used to determine how to interpret different modifier keys) to fail. Use navigator.platform instead, which should be more stable. http://stackoverflow.com/a/19883965/33213 --- include/keyboard.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/keyboard.js b/include/keyboard.js index 3fde55bb..6bea9b53 100644 --- a/include/keyboard.js +++ b/include/keyboard.js @@ -18,13 +18,13 @@ var kbdUtil = (function() { }; function isMac() { - return navigator && !!(/macintosh/i).exec(navigator.appVersion); + return navigator && !!(/mac/i).exec(navigator.platform); } function isWindows() { - return navigator && !!(/windows/i).exec(navigator.appVersion); + return navigator && !!(/win/i).exec(navigator.platform); } function isLinux() { - return navigator && !!(/linux/i).exec(navigator.appVersion); + return navigator && !!(/linux/i).exec(navigator.platform); } // Return true if a modifier which is not the specified char modifier (and is not shift) is down