Skip to content

Commit

Permalink
Fixed handling of keys that are translated unintentionally.
Browse files Browse the repository at this point in the history
  • Loading branch information
najlkin committed Sep 12, 2024
1 parent 9e60e60 commit 7abcc9f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ void SdlWindow::keyDownEvent(SDL_Keysym& ks)
{
lastKeyDownProcessed = false;
lastKeyDownMods = ks.mod;
lastKeyDownChar = scan_name[0];
return;
}
// If the key is not in the range [32,127) then we processed the event here.
Expand Down Expand Up @@ -309,7 +310,13 @@ void SdlWindow::textInputEvent(const SDL_TextInputEvent &tie)
// This event follows a keyDown event where we've recorded if the event was
// processed in keyDownEvent(). If it was not processed, we do it here.
if (lastKeyDownProcessed) { return; }
const char c = tie.text[0];
char c = tie.text[0];
if (!onKeyDown[c])
{
// If the key was translated to something that is not handled, return to
// the physical key passed in the keyDown event.
c = lastKeyDownChar;
}
if (onKeyDown[c])
{
onKeyDown[c](lastKeyDownMods & ~(KMOD_CAPS | KMOD_LSHIFT | KMOD_RSHIFT));
Expand Down
1 change: 1 addition & 0 deletions lib/sdl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class SdlWindow
bool screenshot_convert;
bool lastKeyDownProcessed;
Uint16 lastKeyDownMods;
char lastKeyDownChar;

// internal event handlers
void windowEvent(SDL_WindowEvent& ew);
Expand Down

0 comments on commit 7abcc9f

Please sign in to comment.