Skip to content

Commit

Permalink
Use scancode from key event for mapping release events to the keypad
Browse files Browse the repository at this point in the history
Fixes #348
  • Loading branch information
Vogtinator committed Oct 8, 2024
1 parent 7b54e65 commit d792dd9
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions qtkeypadbridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,17 @@ void keyToKeypad(QKeyEvent *event)
,{Qt::Key_Return, keymap::enter}
};

// Determine virtual key that correspond to the key we got
auto vkey = event->nativeVirtualKey();
// Determine physical key that correspond to the key we got,
// to be able to get releases reliably if modifiers change in between:
// Press shift, press 2 (-> "), release shift, release 2 (-> 2)
// results in press of 2 but release of " (example for de layout).
auto physkey = event->nativeScanCode();
if (physkey < 1)
physkey = event->key(); // (Bad) fallback to the virtual key if needed

// nativeVirtualKey should be working everywhere, but just in case it's not
if (vkey == 0 || vkey == 1)
vkey = event->nativeScanCode();
auto pressed = pressed_keys.find(physkey);

// If neither of them worked then simply use key code
if (vkey == 0 || vkey == 1)
vkey = event->key();

auto pressed = pressed_keys.find(vkey);

// If vkey is already pressed, then this must the the release event
// If physkey is already pressed, then this must the the release event
if (pressed != pressed_keys.end())
{
setKeypad(*pressed, false);
Expand Down Expand Up @@ -197,7 +194,7 @@ void keyToKeypad(QKeyEvent *event)

if (translated != QtKeyMap.end())
{
pressed_keys.insert(vkey, *translated);
pressed_keys.insert(physkey, *translated);
setKeypad(*translated, true);
}
}
Expand Down

0 comments on commit d792dd9

Please sign in to comment.