mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 18:15:28 -04:00
Cleanup MapNativeKey for Windows
This commit is contained in:
parent
8a0c0850ca
commit
6ad7ba4bd7
40
src/Window.c
40
src/Window.c
@ -475,7 +475,20 @@ static const cc_uint8 key_map[14 * 16] = {
|
|||||||
KEY_TILDE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
KEY_TILDE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_LBRACKET, KEY_BACKSLASH, KEY_RBRACKET, KEY_QUOTE, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_LBRACKET, KEY_BACKSLASH, KEY_RBRACKET, KEY_QUOTE, 0,
|
||||||
};
|
};
|
||||||
static int MapNativeKey(WPARAM key) { return key < Array_Elems(key_map) ? key_map[key] : 0; }
|
static int MapNativeKey(WPARAM key, LPARAM meta) {
|
||||||
|
LPARAM ext = meta & (1UL << 24);
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case VK_CONTROL:
|
||||||
|
return ext ? KEY_RCTRL : KEY_LCTRL;
|
||||||
|
case VK_MENU:
|
||||||
|
return ext ? KEY_RALT : KEY_LALT;
|
||||||
|
case VK_RETURN:
|
||||||
|
return ext ? KEY_KP_ENTER : KEY_ENTER;
|
||||||
|
default:
|
||||||
|
return key < Array_Elems(key_map) ? key_map[key] : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void RefreshWindowBounds(void) {
|
static void RefreshWindowBounds(void) {
|
||||||
RECT rect;
|
RECT rect;
|
||||||
@ -602,13 +615,10 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara
|
|||||||
To combat this, we are going to release both keys when either is released. Hacky, but should work.
|
To combat this, we are going to release both keys when either is released. Hacky, but should work.
|
||||||
Win95 does not distinguish left/right key constants (GetAsyncKeyState returns 0).
|
Win95 does not distinguish left/right key constants (GetAsyncKeyState returns 0).
|
||||||
In this case, both keys will be reported as pressed. */
|
In this case, both keys will be reported as pressed. */
|
||||||
LPARAM ext = lParam & (1UL << 24);
|
|
||||||
|
|
||||||
cc_bool lShiftDown, rShiftDown;
|
cc_bool lShiftDown, rShiftDown;
|
||||||
int key;
|
int key;
|
||||||
switch (wParam)
|
|
||||||
{
|
if (wParam == VK_SHIFT) {
|
||||||
case VK_SHIFT:
|
|
||||||
/* The behavior of this key is very strange. Unlike Control and Alt, there is no extended bit
|
/* The behavior of this key is very strange. Unlike Control and Alt, there is no extended bit
|
||||||
to distinguish between left and right keys. Moreover, pressing both keys and releasing one
|
to distinguish between left and right keys. Moreover, pressing both keys and releasing one
|
||||||
may result in both keys being held down (but not always).*/
|
may result in both keys being held down (but not always).*/
|
||||||
@ -619,23 +629,11 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara
|
|||||||
Input_SetPressed(KEY_LSHIFT, lShiftDown);
|
Input_SetPressed(KEY_LSHIFT, lShiftDown);
|
||||||
Input_SetPressed(KEY_RSHIFT, rShiftDown);
|
Input_SetPressed(KEY_RSHIFT, rShiftDown);
|
||||||
}
|
}
|
||||||
return 0;
|
} else {
|
||||||
|
key = MapNativeKey(wParam, lParam);
|
||||||
case VK_CONTROL:
|
|
||||||
Input_SetPressed(ext ? KEY_RCTRL : KEY_LCTRL, pressed);
|
|
||||||
return 0;
|
|
||||||
case VK_MENU:
|
|
||||||
Input_SetPressed(ext ? KEY_RALT : KEY_LALT, pressed);
|
|
||||||
return 0;
|
|
||||||
case VK_RETURN:
|
|
||||||
Input_SetPressed(ext ? KEY_KP_ENTER : KEY_ENTER, pressed);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
default:
|
|
||||||
key = MapNativeKey(wParam);
|
|
||||||
if (key) Input_SetPressed(key, pressed);
|
if (key) Input_SetPressed(key, pressed);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case WM_SYSCHAR:
|
case WM_SYSCHAR:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user