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



  • 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();
    }
    @


  • Lifetime Qt Champion

    Hi,

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



  • 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;
    

    }
    @



  • [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.


  • Lifetime Qt Champion

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.