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. [SOLVED]Sytem-wide Hotkey Shortcut(Windows) : Works but locks window?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Sytem-wide Hotkey Shortcut(Windows) : Works but locks window?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 4.7k 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.
  • W Offline
    W Offline
    weblife
    wrote on last edited by
    #1

    I am trying to figure a way I can use a system wide hotkey in my application. I have provided working code below but my issue is because it's in a while() loop. This is causing the windows to lock up and become disabled, however functions still get processed depending on the wParam I set for each hotkey.

    I will continue to find a way to do this without the loop but figured I could appeal to the community being there is a request for a data type to do this "QDesktopShortcut.":https://bugreports.qt-project.org/browse/QTBUG-5183

    @
    #define MOD_NOREPEAT 0x4000
    #define MOD_ALT 0x0001

    #include "mainwindow.h"
    #include <QApplication>
    #include "stdafx.h"
    #include <QDebug>

    int main(int argc, char *argv[])
    {
    RegisterHotKey(NULL,1,MOD_ALT | MOD_NOREPEAT,0x42);
    RegisterHotKey(NULL,2,MOD_ALT | MOD_NOREPEAT,0x44);
    MSG msg;
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    while(GetMessage(&msg,NULL,0,0)){
    if (msg.message == WM_HOTKEY){
    if (msg.wParam == 1)qDebug() << "Hot Key activated : ALT + B";
    if (msg.wParam == 2) qDebug() << "Hot Key activated : ALT + D";
    }
    }
    return a.exec();
    }
    @

    Brandon Clark
    www.themindspot.com

    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

      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
      • W Offline
        W Offline
        weblife
        wrote on last edited by
        #3

        Solved! Thank you to "terenty":http://qt-project.org/forums/viewthread/27762
        @
        #define MOD_NOREPEAT 0x4000
        #define MOD_ALT 0x0001

        #include "stdafx.h"
        #include <QDebug>
        #include "mainwindow.h"
        #include <QApplication>

        int main(int argc, char *argv[])
        {
        RegisterHotKey(NULL,1,MOD_ALT | MOD_NOREPEAT,0x42);
        RegisterHotKey(NULL,2,MOD_ALT | MOD_NOREPEAT,0x44);

        QApplication a(argc, argv);
        MainWindow w;
        w.show();
        
        QApplication::processEvents();
        
        MSG msg;
        while(GetMessage(&msg,NULL,0,0)){
            TranslateMessage(&msg);
            DispatchMessage(&msg);
            if (msg.message == WM_HOTKEY){
                if (msg.wParam == 1) qDebug() << "Hot Key activated : ALT + B";
                if (msg.wParam == 2) qDebug() << "Hot Key activated : ALT + D";
            }
        }
        return msg.wParam;
        

        }
        @

        Brandon Clark
        www.themindspot.com

        1 Reply Last reply
        0
        • W Offline
          W Offline
          weblife
          wrote on last edited by
          #4

          [quote author="SGaist" date="1385152664"]Hi,

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

          I tried compiling the latest branch for windows but isn't stable. Stable releases don't work with Qt 5.1. It would be a nicer option. I currently am having a exit error with my method. Pretty sure I need to find a way to exit the while loop on exit.

          Brandon Clark
          www.themindspot.com

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

            You should then try to ask on the libQxt user mailing list about their state regarding Qt 5

            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

            • Login

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