Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use scancode from key event for mapping release events to the keypad #349

Merged
merged 1 commit into from
Oct 12, 2024
Merged
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: 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
Loading