Skip to contentSkip to conversation

Fixes key mapping so all keys work

PATCH Superseded Programmingkid 2 participants 2 messages Jan 14, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fixes key mapping so all keys work

This patch allows for all the keys on an Apple extended keyboard to work in QEMU.

---
 ui/cocoa.m |   29 ++++++++++++++++++++---------
 1 files changed, 20 insertions(+), 9 deletions(-)
ui/cocoa.m +20 -9
index c8535a3..afac987 100644
@@ -128,18 +128,26 @@ int keymap[] =
     14, //  51      0x33    0x0e            BKSP    QZ_BACKSPACE
     0,  //  52      0x34    Undefined
     1,  //  53      0x35    0x01            ESC     QZ_ESCAPE
-    220, // 54      0x36    0xdc    E0,5C   R GUI   QZ_RMETA
-    219, // 55      0x37    0xdb    E0,5B   L GUI   QZ_LMETA
+    219,//  54      0x36                            QZ_RMETA
+    219,//  55      0x37                            QZ_LMETA
     42, //  56      0x38    0x2a            L SHFT  QZ_LSHIFT
     58, //  57      0x39    0x3a            CAPS    QZ_CAPSLOCK
     56, //  58      0x3A    0x38            L ALT   QZ_LALT
     29, //  59      0x3B    0x1d            L CTRL  QZ_LCTRL
-    54, //  60      0x3C    0x36            R SHFT  QZ_RSHIFT
-    184,//  61      0x3D    0xb8    E0,38   R ALT   QZ_RALT
-    157,//  62      0x3E    0x9d    E0,1D   R CTRL  QZ_RCTRL
+
+    /*
+     Map right shift, control, option, and command keys to left counterpart
+     to improve compatibility with Mac OS.
+    */
+
+    42, //  60      0x3C    0x36            R SHFT  QZ_RSHIFT
+    56, //  61      0x3D    0xb8    E0,38   R ALT   QZ_RALT
+    29, //  62      0x3E    0x9d    E0,1D   R CTRL  QZ_RCTRL
+
+
     0,  //  63      0x3F    Undefined
     0,  //  64      0x40    Undefined
-    0,  //  65      0x41    Undefined
+    0x53,// 65      0x41                                 Keypad .
     0,  //  66      0x42    Undefined
     55, //  67      0x43    0x37            KP *    QZ_KP_MULTIPLY
     0,  //  68      0x44    Undefined
@@ -150,12 +158,12 @@ int keymap[] =
     0,  //  73      0x49    Undefined
     0,  //  74      0x4A    Undefined
     181,//  75      0x4B    0xb5    E0,35   KP /    QZ_KP_DIVIDE
-    152,//  76      0x4C    0x9c    E0,1C   KP EN   QZ_KP_ENTER
+    0xe01c, //152,//  76      0x4C    0x9c    E0,1C   KP EN   QZ_KP_ENTER
     0,  //  77      0x4D    undefined
     74, //  78      0x4E    0x4a            KP -    QZ_KP_MINUS
     0,  //  79      0x4F    Undefined
     0,  //  80      0x50    Undefined
-    0,  //  81      0x51                            QZ_KP_EQUALS
+    13, //  81      0x51                            QZ_KP_EQUALS
     82, //  82      0x52    0x52            KP 0    QZ_KP0
     79, //  83      0x53    0x4f            KP 1    QZ_KP1
     80, //  84      0x54    0x50            KP 2    QZ_KP2
@@ -201,10 +209,13 @@ int keymap[] =
     205,//  124     0x7C    0xcd    e0,4D   R ARROW QZ_RIGHT
     208,//  125     0x7D    0xd0    E0,50   D ARROW QZ_DOWN
     200,//  126     0x7E    0xc8    E0,48   U ARROW QZ_UP
+
 /* completed according to http://www.libsdl.org/cgi/cvsweb.cgi/SDL12/src/video/quartz/SDL_QuartzKeys.h?rev=1.6&content-type=text/x-cvsweb-markup */
 
-/* Additional 104 Key XP-Keyboard Scancodes from http://www.computer-engineering.org/ps2keyboard/scancodes1.html */
+/* Aditional 104 Key XP-Keyboard Scancodes from http://www.computer-engineering.org/ps2keyboard/scancodes1.html */
 /*
+    219 //          0xdb            e0,5b   L GUI
+    220 //          0xdc            e0,5c   R GUI
     221 //          0xdd            e0,5d   APPS
         //              E0,2A,E0,37         PRNT SCRN
         //              E1,1D,45,E1,9D,C5   PAUSE
Signature · 1 line
1.7.5.4
#1 lore raw
Quoted 13 lines · Programmingkid

This patch allows for all the keys on an Apple extended keyboard to work in QEMU.

---
 ui/cocoa.m |   29 ++++++++++++++++++++---------
 1 files changed, 20 insertions(+), 9 deletions(-)
ui/cocoa.m +0 -0
index c8535a3..afac987 100644

ui/cocoa.m int keymap[] = · line 132

Quoted 7 lines
ui/cocoa.m +2 -2
@@ -128,18 +128,26 @@ int keymap[] =
     14, //  51      0x33    0x0e            BKSP    QZ_BACKSPACE
     0,  //  52      0x34    Undefined
     1,  //  53      0x35    0x01            ESC     QZ_ESCAPE
-    220, // 54      0x36    0xdc    E0,5C   R GUI   QZ_RMETA
-    219, // 55      0x37    0xdb    E0,5B   L GUI   QZ_LMETA
+    219,//  54      0x36                            QZ_RMETA
+    219,//  55      0x37                            QZ_LMETA

This looks wrong: we shouldn't be mapping right meta and left meta to the same thing, they're different keys.

Quoted 6 lines
ui/cocoa.m +0 -2
     42, //  56      0x38    0x2a            L SHFT  QZ_LSHIFT
     58, //  57      0x39    0x3a            CAPS    QZ_CAPSLOCK
     56, //  58      0x3A    0x38            L ALT   QZ_LALT
     29, //  59      0x3B    0x1d            L CTRL  QZ_LCTRL
-    54, //  60      0x3C    0x36            R SHFT  QZ_RSHIFT
-    184,//  61      0x3D    0xb8    E0,38   R ALT   QZ_RALT

ui/cocoa.m int keymap[] = · line 145

Quoted 10 lines
ui/cocoa.m +9 -1
-    157,//  62      0x3E    0x9d    E0,1D   R CTRL  QZ_RCTRL
+
+    /*
+     Map right shift, control, option, and command keys to left counterpart
+     to improve compatibility with Mac OS.
+    */
+
+    42, //  60      0x3C    0x36            R SHFT  QZ_RSHIFT
+    56, //  61      0x3D    0xb8    E0,38   R ALT   QZ_RALT
+    29, //  62      0x3E    0x9d    E0,1D   R CTRL  QZ_RCTRL

Compatibility with Mac OS as a host or as a guest? These are different keys, and if we do this then we won't be able to work correctly with guests that really do treat them as different.

ui/cocoa.m int keymap[] = · line 150

Quoted 6 lines
ui/cocoa.m +3 -1
+
+
     0,  //  63      0x3F    Undefined
     0,  //  64      0x40    Undefined
-    0,  //  65      0x41    Undefined
+    0x53,// 65      0x41                                 Keypad .

Can we be consistent with the other entries, please? SDLi entry in decimal, and appropriate items in the other columns including whatever the QZ_ constant is if we can find it.

ui/cocoa.m int keymap[] = · line 161

Quoted 9 lines
ui/cocoa.m +1 -1
     0,  //  66      0x42    Undefined
     55, //  67      0x43    0x37            KP *    QZ_KP_MULTIPLY
     0,  //  68      0x44    Undefined
@@ -150,12 +158,12 @@ int keymap[] =
     0,  //  73      0x49    Undefined
     0,  //  74      0x4A    Undefined
     181,//  75      0x4B    0xb5    E0,35   KP /    QZ_KP_DIVIDE
-    152,//  76      0x4C    0x9c    E0,1C   KP EN   QZ_KP_ENTER
+    0xe01c, //152,//  76      0x4C    0x9c    E0,1C   KP EN   QZ_KP_ENTER

Only entry in the entire table that's not a one-byte value?

ui/cocoa.m int keymap[] = · line 166

Quoted 6 lines
ui/cocoa.m +1 -1
     0,  //  77      0x4D    undefined
     74, //  78      0x4E    0x4a            KP -    QZ_KP_MINUS
     0,  //  79      0x4F    Undefined
     0,  //  80      0x50    Undefined
-    0,  //  81      0x51                            QZ_KP_EQUALS
+    13, //  81      0x51                            QZ_KP_EQUALS

The keypad = key and the normal = key ought to have different values here. Otherwise the guest can't tell them apart.

ui/cocoa.m int keymap[] = · line 215

Quoted 12 lines
ui/cocoa.m +2 -1
     82, //  82      0x52    0x52            KP 0    QZ_KP0
     79, //  83      0x53    0x4f            KP 1    QZ_KP1
     80, //  84      0x54    0x50            KP 2    QZ_KP2
@@ -201,10 +209,13 @@ int keymap[] =
     205,//  124     0x7C    0xcd    e0,4D   R ARROW QZ_RIGHT
     208,//  125     0x7D    0xd0    E0,50   D ARROW QZ_DOWN
     200,//  126     0x7E    0xc8    E0,48   U ARROW QZ_UP
+
 /* completed according to http://www.libsdl.org/cgi/cvsweb.cgi/SDL12/src/video/quartz/SDL_QuartzKeys.h?rev=1.6&content-type=text/x-cvsweb-markup */
 
-/* Additional 104 Key XP-Keyboard Scancodes from http://www.computer-engineering.org/ps2keyboard/scancodes1.html */
+/* Aditional 104 Key XP-Keyboard Scancodes from http://www.computer-engineering.org/ps2keyboard/scancodes1.html */

This is reintroducing a typo that was fixed back in 2013 (in commit 49b9bd4dc).

ui/cocoa.m int keymap[] = · line 221

Quoted 6 lines
ui/cocoa.m +2 -0
 /*
+    219 //          0xdb            e0,5b   L GUI
+    220 //          0xdc            e0,5c   R GUI
     221 //          0xdd            e0,5d   APPS
         //              E0,2A,E0,37         PRNT SCRN
         //              E1,1D,45,E1,9D,C5   PAUSE

-- PMM