Handling input when application isn't in focus? (Global Input Hotkey?)
-
I want the app that I'm working on to have a bindable hotkey to hide/unhide its main Window (it actually uses a QtQuick style GUI, but this should apply to Qt in general, I think). For example, if the user sets their hide/unhide button to be Super[Meta/Windows]+Home, they should be able to hit that button combo to hide the application; when they want to use it again, they can then unhide it with the same hotkeys.
I have a simple little hide/unhide function (slot):
@/* Toggles application's window visibility.- Returns TRUE if the window exists AND is currently visible. */
bool AppSystem::toggleLauncherVisibility(void)
{
QWindow * window = QGuiApplication::topLevelWindows().front();
if(window)
{
if( isWindowVisible() )
{
window->hide();
return false;
}
else
{
window->showFullScreen();
return true;
}
}
else return false;
}@
However, I've been having an obvious issue with Window 'focus'.. Once I hit the key to hide the app window, my program no longer accepts keyboard inputs so i'm not able to unhide the window. If i understand correctly, there are some things I can do with window modality to force my application to hold keyboard focus, however I don't want my application to handle all keyboard events while hidden - I just want it to be able to recognize the 'unhide' hotkey regardless of its focus state.
How can I achieve this focus/input behavior in Qt/QtQuick/QML?
- Returns TRUE if the window exists AND is currently visible. */
-
Hi,
You might be interested by "this":http://libqxt.bitbucket.org/doc/0.6/qxtglobalshortcut.html
Hope it helps
-
Hi! If you want to track the keyboard input outside of the window, then check out this solution. This solution uses build-in Windows libraries, so you can only implement it in that OS. Unfortunately, it's not that simple on the Unix systems, so currently it'll only work on Windows.