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. How to detect hot-key release event, when using QxtGlobalShortcut ?
Forum Update on Monday, May 27th 2025

How to detect hot-key release event, when using QxtGlobalShortcut ?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 1.3k Views
  • 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.
  • S Offline
    S Offline
    Soul
    wrote on last edited by
    #1

    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 !

    A champion is someone who gets up even when he can´t.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Soul
      wrote on last edited by
      #2

      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 ?

      A champion is someone who gets up even when he can´t.

      mrjjM 1 Reply Last reply
      0
      • S Soul

        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 ?

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Soul
        Hi what platform do u need this on ?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Soul
          wrote on last edited by
          #4

          Hi @mrjj , I just run it on windows.

          A champion is someone who gets up even when he can´t.

          mrjjM 1 Reply Last reply
          0
          • S Soul

            Hi @mrjj , I just run it on windows.

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #5

            @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 += -lUser32

            and GetAsyncKeyState should be not be hard either.
            https://msdn.microsoft.com/en-us/library/windows/desktop/ms646293(v=vs.85).aspx

            1 Reply Last reply
            1
            • S Offline
              S Offline
              Soul
              wrote on last edited by
              #6

              @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 ?

              A champion is someone who gets up even when he can´t.

              mrjjM 1 Reply Last reply
              0
              • S Soul

                @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 ?

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @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.

                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