Re: [AD] Bug in readkey() with numeric keypad?

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


> It will leave the scancode (upper byte) untouched, but simply change the
> ASCII value to 0 if numlock is off.

Sorry, my original patch broke the /, * and Enter keys when numlock was off.
I've attached an updated version of the patch to fix this. It also removes
an unused local variable.

Cheers
Chris
--- wkeybd_old.c	Thu Oct 27 23:23:40 2005
+++ wkeybd.c	Tue Dec  6 18:48:42 2005
@@ -191,7 +191,6 @@
 {
    int mycode;
    int unicode;
-   unsigned int modifiers;
    int n;
    UINT vkey;
    BYTE keystate[256];
@@ -207,43 +206,49 @@
    if (mycode == 0)
       return;
 
-   /* we always want the number characters */
-   keystate[VK_NUMLOCK] |= 1;
+   /* MapVirtualKey always returns the arrow key VKEY, so adjust
+      it if num lock is on */
+   if (keystate[VK_NUMLOCK])
+   {
+     switch (scancode) {
+        case DIK_NUMPAD0:
+           vkey = VK_NUMPAD0;
+           break;
+        case DIK_NUMPAD1:
+           vkey = VK_NUMPAD1;
+           break;
+        case DIK_NUMPAD2:
+           vkey = VK_NUMPAD2;
+           break;
+        case DIK_NUMPAD3:
+           vkey = VK_NUMPAD3;
+           break;
+        case DIK_NUMPAD4:
+           vkey = VK_NUMPAD4;
+           break;
+        case DIK_NUMPAD5:
+           vkey = VK_NUMPAD5;
+           break;
+        case DIK_NUMPAD6:
+           vkey = VK_NUMPAD6;
+           break;
+        case DIK_NUMPAD7:
+           vkey = VK_NUMPAD7;
+           break;
+        case DIK_NUMPAD8:
+           vkey = VK_NUMPAD8;
+           break;
+        case DIK_NUMPAD9:
+           vkey = VK_NUMPAD9;
+           break;
+        case DIK_DECIMAL:
+           vkey = VK_DECIMAL;
+           break;
+     }
+   }
+
    /* what's life without a few special cases */
    switch (scancode) {
-      case DIK_NUMPAD0:
-         vkey = VK_NUMPAD0;
-         break;
-      case DIK_NUMPAD1:
-         vkey = VK_NUMPAD1;
-         break;
-      case DIK_NUMPAD2:
-         vkey = VK_NUMPAD2;
-         break;
-      case DIK_NUMPAD3:
-         vkey = VK_NUMPAD3;
-         break;
-      case DIK_NUMPAD4:
-         vkey = VK_NUMPAD4;
-         break;
-      case DIK_NUMPAD5:
-         vkey = VK_NUMPAD5;
-         break;
-      case DIK_NUMPAD6:
-         vkey = VK_NUMPAD6;
-         break;
-      case DIK_NUMPAD7:
-         vkey = VK_NUMPAD7;
-         break;
-      case DIK_NUMPAD8:
-         vkey = VK_NUMPAD8;
-         break;
-      case DIK_NUMPAD9:
-         vkey = VK_NUMPAD9;
-         break;
-      case DIK_DECIMAL:
-         vkey = VK_DECIMAL;
-         break;
       case DIK_DIVIDE:
          vkey = VK_DIVIDE;
          break;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/