Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions app/streaming/input/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,24 @@ void SdlInputHandler::handleKeyEvent(SDL_KeyboardEvent* event)
break;
case SDL_SCANCODE_GRAVE:
keyCode = 0xC0;
break;
if (event->state == SDL_PRESSED) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Grave key released (swapped)");
LiSendKeyboardEvent2(0x8000 | keyCode,
KEY_ACTION_UP,
modifiers,
shouldNotConvertToScanCodeOnServer ? SS_KBE_FLAG_NON_NORMALIZED : 0);
m_KeysDown.remove(keyCode);
} else {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Grave key pressed (swapped)");
LiSendKeyboardEvent2(0x8000 | keyCode,
KEY_ACTION_DOWN,
modifiers,
shouldNotConvertToScanCodeOnServer ? SS_KBE_FLAG_NON_NORMALIZED : 0);
m_KeysDown.insert(keyCode);
Copy link
Member

@cgutman cgutman Jul 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it might be a broader SDL bug. Can you try one of the SDL test apps (ex: testgles2) with SDL_EVENT_LOGGING=1 environment variable set and see if you get reversed up/down events there too?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the issue lies in the fact that, on Japanese keyboards, when the Hankaku/Zenkaku (half-width/full-width) key is pressed, the OS issues a virtual key code that behaves differently from standard keys — it sends a "true" (released) event and immediately follows it with a "false" (pressed) event. (Scan code 41)

Here are the keyboard inputs obtained using a keylogger.

Datetime Virtual Key Code Scan Code Extended Key Flag Injected Flag Context Code Transition State Flag Timestamp Extra Info Virtual Key Name Display Name
07/06 12:02:44.407 65 30 False False False False 298892765 0 VK_A A key
07/06 12:02:44.551 65 30 False False False True 298892921 0 VK_A A key
07/06 12:02:44.947 66 48 False False False False 298893312 0 VK_B B key
07/06 12:02:45.038 66 48 False False False True 298893406 0 VK_B B key
07/06 12:02:46.342 67 46 False False False False 298894703 0 VK_C C key
07/06 12:02:46.431 67 46 False False False True 298894796 0 VK_C C key
07/06 12:02:47.435 244 41 False False False True 298895796 0 VK_OEM_ENLW OEM specific
07/06 12:02:47.437 243 41 False False False False 298895796 0 VK_OEM_AUTO OEM specific

}
return;
case SDL_SCANCODE_LEFTBRACKET:
keyCode = 0xDB;
break;
Expand All @@ -428,9 +445,9 @@ void SdlInputHandler::handleKeyEvent(SDL_KeyboardEvent* event)
case SDL_SCANCODE_APOSTROPHE:
keyCode = 0xDE;
break;
case SDL_SCANCODE_INTERNATIONAL1:
shouldNotConvertToScanCodeOnServer = true;
case SDL_SCANCODE_NONUSBACKSLASH:
shouldNotConvertToScanCodeOnServer = true;
case SDL_SCANCODE_INTERNATIONAL1:
keyCode = 0xE2;
break;
case SDL_SCANCODE_LANG1:
Expand Down