Windows also remaps the numeric keypad... grrr
authorSam Lantinga <slouken@libsdl.org>
Mon, 11 Feb 2008 21:06:32 +0000
changeset 2317f537a293b3da
parent 2316 5e1f06dc5136
child 2318 0c653886cce7
Windows also remaps the numeric keypad... grrr
src/video/win32/SDL_win32events.c
src/video/win32/SDL_win32keyboard.c
src/video/win32/SDL_win32keyboard.h
     1.1 --- a/src/video/win32/SDL_win32events.c	Mon Feb 11 20:26:22 2008 +0000
     1.2 +++ b/src/video/win32/SDL_win32events.c	Mon Feb 11 21:06:32 2008 +0000
     1.3 @@ -33,8 +33,8 @@
     1.4  #endif
     1.5  
     1.6  /* Masks for processing the windows KEYDOWN and KEYUP messages */
     1.7 -#define REPEATED_KEYMASK	(1<<30)
     1.8 -#define EXTENDED_KEYMASK	(1<<24)
     1.9 +#define REPEATED_KEYMASK    (1<<30)
    1.10 +#define EXTENDED_KEYMASK    (1<<24)
    1.11  
    1.12  #define VK_ENTER    10  /* Keypad Enter ... no VKEY defined? */
    1.13  
    1.14 @@ -52,13 +52,13 @@
    1.15  static WPARAM
    1.16  RemapVKEY(WPARAM wParam, LPARAM lParam)
    1.17  {
    1.18 +    int i;
    1.19 +    BYTE scancode = (BYTE)((lParam >> 16) & 0xFF);
    1.20 +
    1.21      /* Windows remaps alphabetic keys based on current layout.
    1.22         We try to provide USB scancodes, so undo this mapping.
    1.23       */
    1.24      if (wParam >= 'A' && wParam <= 'Z') {
    1.25 -        BYTE scancode = (BYTE)((lParam >> 16) & 0xFF);
    1.26 -        int i;
    1.27 -
    1.28          if (scancode != alpha_scancodes[wParam - 'A']) {
    1.29              for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) {
    1.30                  if (scancode == alpha_scancodes[i]) {
    1.31 @@ -68,6 +68,15 @@
    1.32              }
    1.33          }
    1.34      }
    1.35 +
    1.36 +    /* Keypad keys are a little trickier, we always scan for them. */
    1.37 +    for (i = 0; i < SDL_arraysize(keypad_scancodes); ++i) {
    1.38 +        if (scancode == keypad_scancodes[i]) {
    1.39 +            wParam = VK_NUMPAD0+i;
    1.40 +            break;
    1.41 +        }
    1.42 +    }
    1.43 +
    1.44      return wParam;
    1.45  }
    1.46  
     2.1 --- a/src/video/win32/SDL_win32keyboard.c	Mon Feb 11 20:26:22 2008 +0000
     2.2 +++ b/src/video/win32/SDL_win32keyboard.c	Mon Feb 11 21:06:32 2008 +0000
     2.3 @@ -41,6 +41,9 @@
     2.4      30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24,
     2.5      25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44
     2.6  };
     2.7 +BYTE keypad_scancodes[10] = {
     2.8 +    82, 79, 80, 81, 75, 76, 77, 71, 72, 73
     2.9 +};
    2.10  
    2.11  void
    2.12  WIN_InitKeyboard(_THIS)
    2.13 @@ -57,6 +60,13 @@
    2.14  printf("%d = %d\n", i, alpha_scancodes[i]);
    2.15          }
    2.16      }
    2.17 +    if (MapVirtualKey(VK_NUMPAD0, MAPVK_VK_TO_VSC) != keypad_scancodes[0]) {
    2.18 +printf("Fixing keypad scancode map!\nPlease send the following 10 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
    2.19 +        for (i = 0; i < SDL_arraysize(keypad_scancodes); ++i) {
    2.20 +            keypad_scancodes[i] = MapVirtualKey(VK_NUMPAD0+i, MAPVK_VK_TO_VSC);
    2.21 +printf("%d = %d\n", i, keypad_scancodes[i]);
    2.22 +        }
    2.23 +    }
    2.24  
    2.25      data->key_layout = win32_scancode_table;
    2.26  
     3.1 --- a/src/video/win32/SDL_win32keyboard.h	Mon Feb 11 20:26:22 2008 +0000
     3.2 +++ b/src/video/win32/SDL_win32keyboard.h	Mon Feb 11 21:06:32 2008 +0000
     3.3 @@ -25,6 +25,7 @@
     3.4  #define _SDL_win32keyboard_h
     3.5  
     3.6  extern BYTE alpha_scancodes[26];
     3.7 +extern BYTE keypad_scancodes[10];
     3.8  
     3.9  extern void WIN_InitKeyboard(_THIS);
    3.10  extern void WIN_UpdateKeymap(int keyboard);