Fix wrong initialization of keycode lookup table

Up until now, several keys were assigned the same key value because the `keycode_lookup_table` array wasn't properly initialized. The values at the end of the array were all set to `KeyCode_Ex0 + 1` which is 112. This would cause several key to be treated as the same key.

In my case the key next to the left shift key ( `<` and `>` on AZERTY) was getting the same value as the `Right Windows key`. But I suppose that the left and right windows key would get the same value too (I can't check this as I have only 1 windows key on my keyboard).

This fix just properly initialize the array. I also fixed a typo in a function name: `keycode_physical_translaion_is_wrong` => `keycode_physical_translation_is_wrong`.
This commit is contained in:
Simon Anciaux 2024-08-28 19:09:01 +02:00 committed by Peter Slattery
parent f3dc516704
commit dfce9bf369
1 changed files with 3 additions and 3 deletions

View File

@ -781,12 +781,12 @@ win32_keycode_init(void){
keycode_lookup_table[VK_NUMPAD9] = KeyCode_NumPad9;
for (i32 i = 0xDF; i < 0xFF; i += 1){
keycode_lookup_table[i] = KeyCode_Ex0 + 1;
keycode_lookup_table[i] = KeyCode_Ex0 + i - 0xDF;
}
}
internal b32
keycode_physical_translaion_is_wrong(u64 vk){
keycode_physical_translation_is_wrong(u64 vk){
b32 result = false;
switch (vk){
case VK_UP: case VK_DOWN: case VK_LEFT: case VK_RIGHT:
@ -1225,7 +1225,7 @@ win32_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
u64 vk = wParam;
if (win32vars.key_mode == KeyMode_Physical &&
!keycode_physical_translaion_is_wrong(vk)){
!keycode_physical_translation_is_wrong(vk)){
UINT scan_code = ((lParam >> 16) & bitmask_8);
vk = MapVirtualKeyEx(scan_code, MAPVK_VSC_TO_VK_EX, win32vars.kl_universal);
}