src/video/win32/SDL_win32keyboard.c
changeset 2308 514f7c1651fc
parent 1895 c121d94672cb
child 2311 54e21acfec5a
--- a/src/video/win32/SDL_win32keyboard.c	Thu Feb 07 16:14:43 2008 +0000
+++ b/src/video/win32/SDL_win32keyboard.c	Fri Feb 08 08:35:49 2008 +0000
@@ -24,6 +24,7 @@
 #include "SDL_win32video.h"
 
 #include "../../events/SDL_keyboard_c.h"
+#include "../../events/scancodes_win32.h"
 
 void
 WIN_InitKeyboard(_THIS)
@@ -31,8 +32,41 @@
     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     SDL_Keyboard keyboard;
 
+    data->key_layout = win32_scancode_table;
+
     SDL_zero(keyboard);
     data->keyboard = SDL_AddKeyboard(&keyboard, -1);
+    WIN_UpdateKeymap(_this);
+
+    SDL_SetScancodeName(SDL_SCANCODE_APPLICATION, "Menu");
+    SDL_SetScancodeName(SDL_SCANCODE_LGUI, "Left Windows");
+    SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Windows");
+}
+
+void
+WIN_UpdateKeymap(_THIS)
+{
+    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+    int i;
+    SDL_scancode scancode;
+    SDLKey keymap[SDL_NUM_SCANCODES];
+
+    SDL_GetDefaultKeymap(keymap);
+
+    for (i = 0; i < SDL_arraysize(win32_scancode_table); i++) {
+
+        /* Make sure this scancode is a valid character scancode */
+        scancode = win32_scancode_table[i];
+        if (scancode == SDL_SCANCODE_UNKNOWN ||
+            (keymap[scancode] & SDLK_SCANCODE_MASK)) {
+            continue;
+        }
+#ifndef MAPVK_VK_TO_CHAR
+#define MAPVK_VK_TO_CHAR    2
+#endif
+        keymap[scancode] = (MapVirtualKey(i, MAPVK_VK_TO_CHAR) & 0x7FFF);
+    }
+    SDL_SetKeymap(data->keyboard, 0, keymap, SDL_NUM_SCANCODES);
 }
 
 void