mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-01 23:07:45 +08:00
WIN_UpdateKeymap: cleanup code a bit
This commit is contained in:
committed by
Sam Lantinga
parent
0a86f8eb6e
commit
1973edb9b7
@@ -115,13 +115,15 @@ void WIN_UpdateKeymap(SDL_bool send_event)
|
|||||||
int i;
|
int i;
|
||||||
SDL_Scancode scancode;
|
SDL_Scancode scancode;
|
||||||
SDL_Keycode keymap[SDL_NUM_SCANCODES];
|
SDL_Keycode keymap[SDL_NUM_SCANCODES];
|
||||||
|
BYTE keyboardState[256] = { 0 };
|
||||||
|
WCHAR buffer[16];
|
||||||
|
|
||||||
SDL_GetDefaultKeymap(keymap);
|
SDL_GetDefaultKeymap(keymap);
|
||||||
WIN_ResetDeadKeys();
|
WIN_ResetDeadKeys();
|
||||||
|
|
||||||
for (i = 0; i < SDL_arraysize(windows_scancode_table); i++) {
|
for (i = 0; i < SDL_arraysize(windows_scancode_table); i++) {
|
||||||
Uint8 vk;
|
int vk, sc, result;
|
||||||
Uint16 sc;
|
Uint32 *ch = 0;
|
||||||
|
|
||||||
/* Make sure this scancode is a valid character scancode */
|
/* Make sure this scancode is a valid character scancode */
|
||||||
scancode = windows_scancode_table[i];
|
scancode = windows_scancode_table[i];
|
||||||
@@ -142,29 +144,16 @@ void WIN_UpdateKeymap(SDL_bool send_event)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Always map VK_A..VK_Z to SDLK_a..SDLK_z codes.
|
result = ToUnicode(vk, sc, keyboardState, buffer, 16, 0);
|
||||||
* This was behavior with MapVirtualKey(MAPVK_VK_TO_CHAR). */
|
|
||||||
//if (vk >= 'A' && vk <= 'Z') {
|
|
||||||
// keymap[scancode] = SDLK_a + (vk - 'A');
|
|
||||||
//} else {
|
|
||||||
{
|
|
||||||
BYTE keyboardState[256] = { 0 };
|
|
||||||
WCHAR buffer[16] = { 0 };
|
|
||||||
Uint32 *ch = 0;
|
|
||||||
int result = ToUnicode(vk, sc, keyboardState, buffer, 16, 0);
|
|
||||||
buffer[SDL_abs(result)] = 0;
|
buffer[SDL_abs(result)] = 0;
|
||||||
|
|
||||||
/* Convert UTF-16 to UTF-32 code points */
|
/* Convert UTF-16 to UTF-32 code points */
|
||||||
ch = (Uint32 *)SDL_iconv_string("UTF-32LE", "UTF-16LE", (const char *)buffer, (SDL_abs(result) + 1) * sizeof(WCHAR));
|
ch = (Uint32 *)SDL_iconv_string("UTF-32LE", "UTF-16LE", (const char *)buffer, (SDL_abs(result) + 1) * sizeof(WCHAR));
|
||||||
if (ch) {
|
if (ch) {
|
||||||
if (ch[0] != 0 && ch[1] != 0) {
|
/* Windows keyboard layouts can emit several UTF-32 code points on a single key press.
|
||||||
/* We have several UTF-32 code points on a single key press.
|
* Use <U+FFFD REPLACEMENT CHARACTER> since we cannot fit into single SDL_Keycode value in SDL keymap.
|
||||||
* Cannot fit into single SDL_Keycode in keymap.
|
* See https://kbdlayout.info/features/ligatures for a list of such keys. */
|
||||||
* See https://kbdlayout.info/features/ligatures */
|
keymap[scancode] = ch[1] == 0 ? ch[0] : 0xfffd;
|
||||||
keymap[scancode] = 0xfffd; /* U+FFFD REPLACEMENT CHARACTER */
|
|
||||||
} else {
|
|
||||||
keymap[scancode] = ch[0];
|
|
||||||
}
|
|
||||||
SDL_free(ch);
|
SDL_free(ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +161,6 @@ void WIN_UpdateKeymap(SDL_bool send_event)
|
|||||||
WIN_ResetDeadKeys();
|
WIN_ResetDeadKeys();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES, send_event);
|
SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES, send_event);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user