]> git.proxmox.com Git - mirror_novnc.git/commitdiff
Better key identifiers
authorJesper Dam <jalf@medical-insight.com>
Wed, 12 Mar 2014 09:08:14 +0000 (10:08 +0100)
committerJesper Dam <jalf@medical-insight.com>
Wed, 12 Mar 2014 10:19:56 +0000 (11:19 +0100)
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

index f21f9767bb8fdece741135e41de9f6be64fd655a..3fde55bb08b2c577c33b213bf50fdf6db6e55fcd 100644 (file)
@@ -152,12 +152,15 @@ 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 {
+        else if ('keyCode' in evt) {
             return evt.keyCode;
         }
+        else {
+            return evt.key;
+        }
     }
 
     // Get the most reliable keysym value we can get from a key event