Fix spurious LCtrl on RAlt key pressed
(cherry picked from commit 22c14442e2)
This commit is contained in:
1 parent
e0b0a98c8e
commit
6243a80b3f
1 file changed
+45
@@ -638,6 +638,10 @@ WIN_KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
|
|||||||
if (nCode < 0 || nCode != HC_ACTION) {
|
if (nCode < 0 || nCode != HC_ACTION) {
|
||||||
return CallNextHookEx(NULL, nCode, wParam, lParam);
|
return CallNextHookEx(NULL, nCode, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
if (hookData->scanCode == 0x21d) {
|
||||||
|
// Skip fake LCtrl when RAlt is pressed
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
switch (hookData->vkCode) {
|
switch (hookData->vkCode) {
|
||||||
case VK_LWIN:
|
case VK_LWIN:
|
||||||
@@ -692,6 +696,39 @@ WIN_KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
|
|||||||
|
|
||||||
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
|
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
|
||||||
|
|
||||||
|
|
||||||
|
// Return 1 if spruious LCtrl is pressed
|
||||||
|
// LCtrl is sent when RAltGR is pressed
|
||||||
|
int skip_bad_lcrtl(WPARAM wParam, LPARAM lParam)
|
||||||
|
{
|
||||||
|
MSG next_msg;
|
||||||
|
DWORD msg_time;
|
||||||
|
if (wParam != VK_CONTROL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// Is this an extended key (i.e. right key)?
|
||||||
|
if (lParam & 0x01000000)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// Here is a trick: "Alt Gr" sends LCTRL, then RALT. We only
|
||||||
|
// want the RALT message, so we try to see if the next message
|
||||||
|
// is a RALT message. In that case, this is a false LCTRL!
|
||||||
|
msg_time = GetMessageTime();
|
||||||
|
if (PeekMessage(&next_msg, NULL, 0, 0, PM_NOREMOVE)) {
|
||||||
|
if (next_msg.message == WM_KEYDOWN ||
|
||||||
|
next_msg.message == WM_SYSKEYDOWN) {
|
||||||
|
if (next_msg.wParam == VK_MENU &&
|
||||||
|
(next_msg.lParam & 0x01000000) &&
|
||||||
|
next_msg.time == msg_time) {
|
||||||
|
// Next message is a RALT down message, which
|
||||||
|
// means that this is NOT a proper LCTRL message!
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
LRESULT CALLBACK
|
LRESULT CALLBACK
|
||||||
WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
@@ -1006,6 +1043,10 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||||||
case WM_KEYDOWN:
|
case WM_KEYDOWN:
|
||||||
case WM_SYSKEYDOWN:
|
case WM_SYSKEYDOWN:
|
||||||
{
|
{
|
||||||
|
if (skip_bad_lcrtl(wParam, lParam)) {
|
||||||
|
returnCode = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
SDL_Scancode code = WindowsScanCodeToSDLScanCode(lParam, wParam);
|
SDL_Scancode code = WindowsScanCodeToSDLScanCode(lParam, wParam);
|
||||||
const Uint8 *keyboardState = SDL_GetKeyboardState(NULL);
|
const Uint8 *keyboardState = SDL_GetKeyboardState(NULL);
|
||||||
|
|
||||||
@@ -1028,6 +1069,10 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||||||
case WM_SYSKEYUP:
|
case WM_SYSKEYUP:
|
||||||
case WM_KEYUP:
|
case WM_KEYUP:
|
||||||
{
|
{
|
||||||
|
if (skip_bad_lcrtl(wParam, lParam)) {
|
||||||
|
returnCode = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
SDL_Scancode code = WindowsScanCodeToSDLScanCode(lParam, wParam);
|
SDL_Scancode code = WindowsScanCodeToSDLScanCode(lParam, wParam);
|
||||||
const Uint8 *keyboardState = SDL_GetKeyboardState(NULL);
|
const Uint8 *keyboardState = SDL_GetKeyboardState(NULL);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user