[Spice-devel] [PATCH spice-html5] Adjust the presentation of two byte scan codes.

Jeremy White jwhite at codeweavers.com
Mon Aug 5 14:47:05 UTC 2019


The previous implementation worked strictly due to a bug which would
luckily generate roughly the right scan codes, although we would send
more codes than required.

For example, the old implementation would send 0xdf48e0 for 'up key down'
and '0xdfc8e0' for 'up key up'.  Essentially, it stored the bytes
in reverse order and had a bug while flipping them.

This code stores them in the order we transmit them which simplifies
the code.

Signed-off-by: Jeremy White <jwhite at codeweavers.com>
---
 src/utils.js | 40 ++++++++++++++++++----------------------
 1 file changed, 18 insertions(+), 22 deletions(-)

diff --git a/src/utils.js b/src/utils.js
index 1874e97..af8e574 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -157,6 +157,7 @@ common_scanmap[16]                 = KeyNames.KEY_ShiftL;
 common_scanmap[17]                 = KeyNames.KEY_LCtrl;
 common_scanmap[18]                 = KeyNames.KEY_Alt;
 common_scanmap[20]                 = KeyNames.KEY_CapsLock;
+common_scanmap[44]                 = KeyNames.KEY_SysReqest;
 common_scanmap[144]                = KeyNames.KEY_NumLock;
 common_scanmap[112]                = KeyNames.KEY_F1;
 common_scanmap[113]                = KeyNames.KEY_F2;
@@ -174,19 +175,18 @@ common_scanmap[123]                = KeyNames.KEY_F12;
 /* These extended scancodes do not line up with values from atKeynames */
 common_scanmap[42]                 = 99;
 common_scanmap[19]                 = 101;    // Break
-common_scanmap[111]                = 0xE035; // KP_Divide
-common_scanmap[106]                = 0xE037; // KP_Multiply
-common_scanmap[36]                 = 0xE047; // Home
-common_scanmap[38]                 = 0xE048; // Up
-common_scanmap[33]                 = 0xE049; // PgUp
-common_scanmap[37]                 = 0xE04B; // Left
-common_scanmap[39]                 = 0xE04D; // Right
-common_scanmap[35]                 = 0xE04F; // End
-common_scanmap[40]                 = 0xE050; // Down
-common_scanmap[34]                 = 0xE051; // PgDown
-common_scanmap[45]                 = 0xE052; // Insert
-common_scanmap[46]                 = 0xE053; // Delete
-common_scanmap[44]                 = 0x2A37; // Print
+common_scanmap[111]                = 0xE0 | (KeyNames.KEY_Slash << 8);// KP_Divide
+common_scanmap[106]                = 0xE0 | (KeyNames.KEY_KP_Multiply << 8); // KP_Multiply
+common_scanmap[36]                 = 0xE0 | (KeyNames.KEY_KP_7 << 8); // Home
+common_scanmap[38]                 = 0xE0 | (KeyNames.KEY_KP_8 << 8); // Up
+common_scanmap[33]                 = 0xE0 | (KeyNames.KEY_KP_9 << 8); // PgUp
+common_scanmap[37]                 = 0xE0 | (KeyNames.KEY_KP_4 << 8); // Left
+common_scanmap[39]                 = 0xE0 | (KeyNames.KEY_KP_6 << 8); // Right
+common_scanmap[35]                 = 0xE0 | (KeyNames.KEY_KP_1 << 8); // End
+common_scanmap[40]                 = 0xE0 | (KeyNames.KEY_KP_2 << 8); // Down
+common_scanmap[34]                 = 0xE0 | (KeyNames.KEY_KP_3 << 8); // PgDown
+common_scanmap[45]                 = 0xE0 | (KeyNames.KEY_KP_0 << 8); // Insert
+common_scanmap[46]                 = 0xE0 | (KeyNames.KEY_KP_Decimal << 8); // Delete
 
 /* These are not common between ALL browsers but are between Firefox and DOM3 */
 common_scanmap['1'.charCodeAt(0)]  = KeyNames.KEY_1;
@@ -221,9 +221,9 @@ common_scanmap[222]                = KeyNames.KEY_Quote;
 common_scanmap[219]                = KeyNames.KEY_LBrace;
 common_scanmap[221]                = KeyNames.KEY_RBrace;
 
-common_scanmap[91]                 = 0xE05B; //KeyNames.KEY_LMeta
-common_scanmap[92]                 = 0xE05C; //KeyNames.KEY_RMeta
-common_scanmap[93]                 = 0xE05D; //KeyNames.KEY_Menu
+common_scanmap[91]                 = 0xE0 | (0x5B << 8); //KeyNames.KEY_LMeta
+common_scanmap[92]                 = 0xE0 | (0x5C << 8); //KeyNames.KEY_RMeta
+common_scanmap[93]                 = 0xE0 | (0x5D << 8); //KeyNames.KEY_Menu
 
 /* Firefox/Mozilla codes */
 var firefox_scanmap = [];
@@ -260,11 +260,7 @@ function keycode_to_start_scan(code)
         return 0;
     }
 
-    if (scancode < 0x100) {
-        return scancode;
-    } else {
-        return 0xe0 | ((scancode - 0x100) << 8);
-    }
+    return scancode;
 }
 
 function keycode_to_end_scan(code)
@@ -276,7 +272,7 @@ function keycode_to_end_scan(code)
     if (scancode < 0x100) {
         return scancode | 0x80;
     } else {
-        return 0x80e0 | ((scancode - 0x100) << 8);
+        return scancode | 0x8000;
     }
 }
 
-- 
2.20.1



More information about the Spice-devel mailing list