Solved How to detect hot-key release event, when using QxtGlobalShortcut ?
-
My application is as below:
1>When the hot key is pressed , then the application start to record voice.
2>When the hot key is released, then the application stop record the voice.Note : The application may not have the focus.
I have tried the QxtGlobalShortcut class, but it seems no "signal" when the hot key released.
The code is below:
QxtGlobalShortcut *shortcut = new QxtGlobalShortcut(); if(shortcut->setShortcut(QKeySequence("Shift+1"))){ qDebug("Create short cut done\r\n"); } else{ qDebug("Create short cut failed\r\n"); } QObject::connect(shortcut, SIGNAL(activated()), this, SLOT(onInputKeyPressed())); shortcut->setEnabled();
Is there any good idea ? Thanks in advance !
-
I found an appearance the hot-key event always occurres when I hold the key.
Is this a good way which to create a timer to detect the key release ? -
@Soul
Hi what platform do u need this on ? -
Hi @mrjj , I just run it on windows.
-
@Soul
hi
Ok. so not an issue if not crossplatform ?You can use RegisterHotkey to detect the key going down, then use polling (with timer) with GetAsyncKeyState
to see it goes up. I did not find any way to use WM_HOTKEY and get event on
button released. It was suggested to use DLL with SetWindowsHookEx()
but it seems like much work for 1 hotkey.The RegisterHotkey is pretty trivial
http://amin-ahmadi.com/2015/11/14/how-to-use-system-wide-hotkeys-in-your-qt-application/
note the LIBS += -lUser32and GetAsyncKeyState should be not be hard either.
https://msdn.microsoft.com/en-us/library/windows/desktop/ms646293(v=vs.85).aspx -
@mrjj
Hi , thank you for your reply . I think GetAsyncKeyState is the best solution for me.
By the way, If I want to make it corssplatform, what shall I do ? Could I have your suggestion ? -
@Soul
Hi
I never found a linux version that could tell when key released.
Those i tested only gave Activated() signal.https://github.com/mitei/qglobalshortcut
Im sure its possible with native linux programming but i never looked more into it.