diff --git a/samples/hotkey/hotkey.cpp b/samples/hotkey/hotkey.cpp index ce30336b8..34fe99efc 100644 --- a/samples/hotkey/hotkey.cpp +++ b/samples/hotkey/hotkey.cpp @@ -20,6 +20,7 @@ HotkeyDialog::HotkeyDialog(QWidget *parent) : setupUi(); setupConnections(); + } HotkeyDialog::~HotkeyDialog() @@ -40,8 +41,17 @@ void HotkeyDialog::keySelectionChanged(BlackMisc::Hardware::CKeyboardKey key) void HotkeyDialog::keySelectionFinished(BlackMisc::Hardware::CKeyboardKey key) { m_lblHotkey->setText(key.toFormattedQString()); - m_keyboard->unregisterAllHotkeys(); - m_keyboard->registerHotkey(key, this, &HotkeyDialog::setPressed); + m_key = key; +} + +void HotkeyDialog::processKeyDown(const BlackMisc::Hardware::CKeyboardKey &key) +{ + if (key == m_key) setPressed(true); +} + +void HotkeyDialog::processKeyUp(const BlackMisc::Hardware::CKeyboardKey &key) +{ + if (key == m_key) setPressed(false); } void HotkeyDialog::setPressed(bool isPressed) @@ -89,5 +99,7 @@ void HotkeyDialog::setupConnections() { connect(m_keyboard, &BlackInput::IKeyboard::keySelectionChanged, this, &HotkeyDialog::keySelectionChanged); connect(m_keyboard, &BlackInput::IKeyboard::keySelectionFinished, this, &HotkeyDialog::keySelectionFinished); + connect(m_keyboard, &BlackInput::IKeyboard::keyDown, this, &HotkeyDialog::processKeyDown); + connect(m_keyboard, &BlackInput::IKeyboard::keyUp, this, &HotkeyDialog::processKeyUp); connect(m_pbSelect, &QPushButton::clicked, this, &HotkeyDialog::selectHotKey); } diff --git a/samples/hotkey/hotkey.h b/samples/hotkey/hotkey.h index de6788b62..9b37c9c09 100644 --- a/samples/hotkey/hotkey.h +++ b/samples/hotkey/hotkey.h @@ -46,6 +46,10 @@ private slots: */ void keySelectionFinished(BlackMisc::Hardware::CKeyboardKey key); + void processKeyDown(const BlackMisc::Hardware::CKeyboardKey &); + + void processKeyUp(const BlackMisc::Hardware::CKeyboardKey &); + private: /*! * \brief Set the key status @@ -58,6 +62,7 @@ private: void setupConnections(); BlackInput::IKeyboard *m_keyboard; + BlackMisc::Hardware::CKeyboardKey m_key; QPushButton *m_pbSelect; QLabel *m_lblHotkey; CLed *m_led;