Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Handling input when application isn't in focus? (Global Input Hotkey?)
Forum Updated to NodeBB v4.3 + New Features

Handling input when application isn't in focus? (Global Input Hotkey?)

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    katanaswordfish
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You might be interested by "this":http://libqxt.bitbucket.org/doc/0.6/qxtglobalshortcut.html

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • lukas_kosinskiL Offline
        lukas_kosinskiL Offline
        lukas_kosinski
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved