Commit 1a34de27 authored by Sam Lantinga's avatar Sam Lantinga

Friggin' Windows remaps alphabetic keys based on keyboard layout.

We try to figure out what the actual layout independent values are.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%402723
parent 69b676ff
...@@ -54,17 +54,12 @@ RemapVKEY(WPARAM wParam, LPARAM lParam) ...@@ -54,17 +54,12 @@ RemapVKEY(WPARAM wParam, LPARAM lParam)
We try to provide USB scancodes, so undo this mapping. We try to provide USB scancodes, so undo this mapping.
*/ */
if (wParam >= 'A' && wParam <= 'Z') { if (wParam >= 'A' && wParam <= 'Z') {
/* Alphabetic scancodes for PC keyboards */
static BYTE scancodes[26] = {
30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24,
25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44
};
BYTE scancode = (lParam >> 16) & 0xFF; BYTE scancode = (lParam >> 16) & 0xFF;
int i; int i;
if (scancode != scancodes[wParam - 'A']) { if (scancode != alpha_scancodes[wParam - 'A']) {
for (i = 0; i < SDL_arraysize(scancodes); ++i) { for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) {
if (scancode == scancodes[i]) { if (scancode == alpha_scancodes[i]) {
wParam = 'A' + i; wParam = 'A' + i;
break; break;
} }
...@@ -448,6 +443,12 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) ...@@ -448,6 +443,12 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
} }
return (0); return (0);
case WM_INPUTLANGCHANGE:
{
WIN_UpdateKeymap(data->videodata->keyboard);
}
return (1);
case WM_GETMINMAXINFO: case WM_GETMINMAXINFO:
{ {
MINMAXINFO *info; MINMAXINFO *info;
......
...@@ -26,17 +26,43 @@ ...@@ -26,17 +26,43 @@
#include "../../events/SDL_keyboard_c.h" #include "../../events/SDL_keyboard_c.h"
#include "../../events/scancodes_win32.h" #include "../../events/scancodes_win32.h"
#ifndef MAPVK_VK_TO_VSC
#define MAPVK_VK_TO_VSC 0
#endif
#ifndef MAPVK_VSC_TO_VK
#define MAPVK_VSC_TO_VK 1
#endif
#ifndef MAPVK_VK_TO_CHAR
#define MAPVK_VK_TO_CHAR 2
#endif
/* Alphabetic scancodes for PC keyboards */
BYTE alpha_scancodes[26] = {
30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24,
25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44
};
void void
WIN_InitKeyboard(_THIS) WIN_InitKeyboard(_THIS)
{ {
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
SDL_Keyboard keyboard; SDL_Keyboard keyboard;
int i;
/* Make sure the alpha scancodes are correct. T isn't usually remapped */
if (MapVirtualKey('T', MAPVK_VK_TO_VSC) != alpha_scancodes['T'-'A']) {
printf("Fixing alpha scancode map, assuming US QWERTY layout!\nPlease send the following 26 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) {
alpha_scancodes[i] = MapVirtualKey('A'+i, MAPVK_VK_TO_VSC);
printf("%d = %d\n", i, alpha_scancodes[i]);
}
}
data->key_layout = win32_scancode_table; data->key_layout = win32_scancode_table;
SDL_zero(keyboard); SDL_zero(keyboard);
data->keyboard = SDL_AddKeyboard(&keyboard, -1); data->keyboard = SDL_AddKeyboard(&keyboard, -1);
WIN_UpdateKeymap(_this); WIN_UpdateKeymap(data->keyboard);
SDL_SetScancodeName(SDL_SCANCODE_APPLICATION, "Menu"); SDL_SetScancodeName(SDL_SCANCODE_APPLICATION, "Menu");
SDL_SetScancodeName(SDL_SCANCODE_LGUI, "Left Windows"); SDL_SetScancodeName(SDL_SCANCODE_LGUI, "Left Windows");
...@@ -44,9 +70,8 @@ WIN_InitKeyboard(_THIS) ...@@ -44,9 +70,8 @@ WIN_InitKeyboard(_THIS)
} }
void void
WIN_UpdateKeymap(_THIS) WIN_UpdateKeymap(int keyboard)
{ {
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
int i; int i;
SDL_scancode scancode; SDL_scancode scancode;
SDLKey keymap[SDL_NUM_SCANCODES]; SDLKey keymap[SDL_NUM_SCANCODES];
...@@ -61,12 +86,16 @@ WIN_UpdateKeymap(_THIS) ...@@ -61,12 +86,16 @@ WIN_UpdateKeymap(_THIS)
(keymap[scancode] & SDLK_SCANCODE_MASK)) { (keymap[scancode] & SDLK_SCANCODE_MASK)) {
continue; continue;
} }
#ifndef MAPVK_VK_TO_CHAR
#define MAPVK_VK_TO_CHAR 2 /* Alphabetic keys are handled specially, since Windows remaps them */
#endif if (i >= 'A' && i <= 'Z') {
keymap[scancode] = (MapVirtualKey(i, MAPVK_VK_TO_CHAR) & 0x7FFF); BYTE vsc = alpha_scancodes[i-'A'];
keymap[scancode] = MapVirtualKey(vsc, MAPVK_VSC_TO_VK) + 0x20;
} else {
keymap[scancode] = (MapVirtualKey(i, MAPVK_VK_TO_CHAR) & 0x7FFF);
}
} }
SDL_SetKeymap(data->keyboard, 0, keymap, SDL_NUM_SCANCODES); SDL_SetKeymap(keyboard, 0, keymap, SDL_NUM_SCANCODES);
} }
void void
......
...@@ -24,8 +24,10 @@ ...@@ -24,8 +24,10 @@
#ifndef _SDL_win32keyboard_h #ifndef _SDL_win32keyboard_h
#define _SDL_win32keyboard_h #define _SDL_win32keyboard_h
extern BYTE alpha_scancodes[26];
extern void WIN_InitKeyboard(_THIS); extern void WIN_InitKeyboard(_THIS);
extern void WIN_UpdateKeymap(_THIS); extern void WIN_UpdateKeymap(int keyboard);
extern void WIN_QuitKeyboard(_THIS); extern void WIN_QuitKeyboard(_THIS);
#endif /* _SDL_win32keyboard_h */ #endif /* _SDL_win32keyboard_h */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment