diff options
-rw-r--r-- | gui/keyboard.h | 6 | ||||
-rw-r--r-- | opentrack/keybinding-worker.cpp | 21 | ||||
-rw-r--r-- | opentrack/shortcuts.cpp | 5 |
3 files changed, 23 insertions, 9 deletions
diff --git a/gui/keyboard.h b/gui/keyboard.h index b840bc78..75226aa3 100644 --- a/gui/keyboard.h +++ b/gui/keyboard.h @@ -22,7 +22,11 @@ public: { if(k.guid != "") { - joystick_button_pressed(k.guid, k.keycode, k.held); + int mods = 0; + if (k.alt) mods |= Qt::AltModifier; + if (k.shift) mods |= Qt::ShiftModifier; + if (k.ctrl) mods |= Qt::ControlModifier; + joystick_button_pressed(k.guid, k.keycode | mods, k.held); } else { diff --git a/opentrack/keybinding-worker.cpp b/opentrack/keybinding-worker.cpp index e9255801..fd777211 100644 --- a/opentrack/keybinding-worker.cpp +++ b/opentrack/keybinding-worker.cpp @@ -68,16 +68,29 @@ KeybindingWorker::KeybindingWorker(std::function<void(Key&)> receiver, WId h) : } void KeybindingWorker::run() { - BYTE keystate[256]; + BYTE keystate[256] = {0}; while (!should_quit) { { + const HRESULT hr = dinkeyboard->GetDeviceState(256, (LPVOID)keystate); + + if (hr != DI_OK) { + qDebug() << "Tracker::run GetDeviceState function failed!" << GetLastError(); + Sleep(25); + continue; + } + } + + { using joy_fn = std::function<void(const QString& guid, int idx, bool held)>; joy_fn f = [&](const QString& guid, int idx, bool held) -> void { Key k; k.keycode = idx; + k.shift = !!(keystate[DIK_LSHIFT] & 0x80 || keystate[DIK_RSHIFT] & 0x80); + k.alt = !!(keystate[DIK_LALT] & 0x80 || keystate[DIK_RALT] & 0x80); + k.ctrl = !!(keystate[DIK_LCONTROL] & 0x80 || keystate[DIK_RCONTROL] & 0x80); k.guid = guid; k.held = held; receiver(k); @@ -85,12 +98,6 @@ void KeybindingWorker::run() { joy_ctx.poll(f); } - - if (dinkeyboard->GetDeviceState(256, (LPVOID)keystate) != DI_OK) { - qDebug() << "Tracker::run GetDeviceState function failed!" << GetLastError(); - Sleep(25); - continue; - } QMutexLocker l(&mtx); diff --git a/opentrack/shortcuts.cpp b/opentrack/shortcuts.cpp index 108b6b3b..6eab6071 100644 --- a/opentrack/shortcuts.cpp +++ b/opentrack/shortcuts.cpp @@ -38,7 +38,10 @@ void Shortcuts::bind_keyboard_shortcut(K &key, key_opts& k) if (k.guid != "") { key.guid = k.guid; - key.keycode = k.button; + key.keycode = k.button & ~Qt::KeyboardModifierMask; + key.ctrl = !!(k.button & Qt::ControlModifier); + key.alt = !!(k.button & Qt::AltModifier); + key.shift = !!(k.button & Qt::ShiftModifier); } else { |