Results 1 to 2 of 2

Thread: Receive HotKey events with QAbstractEventDispatcher?

  1. #1
    Join Date
    Apr 2010
    Posts
    11
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Receive HotKey events with QAbstractEventDispatcher?

    Hello Qt experts,

    I have created an add-on for a game (I use Visual Studio 2008 C++ and Qt 4.6.2.). It works fine!

    Now I want to receive events from keystrokes when in-game (non-windows mode?!). The solution I have made works, but only when the game is not running
    I think it has something to do with the events not being sent to my window any more, so I would like to dig deeper into the Windows event-mechanism.

    The code I made is this:

    Class-Header:
    Qt Code:
    1. #ifndef FACEAPP_H
    2. #define FACEAPP_H
    3.  
    4. #include <QApplication>
    5.  
    6. class FaceApp : public QApplication
    7. {
    8. Q_OBJECT
    9. public:
    10. FaceApp( int &argc, char **argv ) : QApplication( argc, argv ) {}
    11. ~FaceApp() {}
    12.  
    13. void SetupEventFilter( MyClass *window );
    14.  
    15. protected:
    16. bool winEventFilter( MSG * msg, long * result );
    17.  
    18. };
    19.  
    20. #endif // FACEAPP_H
    To copy to clipboard, switch view to plain text mode 

    Implementation:
    Qt Code:
    1. #include "FaceApp.h"
    2. #include "windows.h"
    3. #include <QDebug>
    4.  
    5. //
    6. // Override the Application MessageFilter, to receive messages from the game(s)
    7. //
    8. bool FaceApp::winEventFilter( MSG * msg, long * result )
    9. {
    10. int msgType = msg->message; // test line
    11.  
    12. if (msgType == WM_HOTKEY) {
    13. switch ( msg->wParam ) {
    14. case 777:
    15. qDebug() << "FaceApp::winEventFilter says: HOME pressed";
    16. break;
    17. case 778:
    18. qDebug() << "FaceApp::winEventFilter says: END pressed";
    19. break;
    20. default:
    21. qDebug() << "FaceApp::winEventFilter says: unknown HotKey pressed";
    22. break;
    23. }
    24. }
    25. return( false );
    26. }
    27.  
    28. //
    29. // Setup the EventFilter
    30. //
    31. void FaceApp::SetupEventFilter( MyClass *window ) {
    32.  
    33. if ( RegisterHotKey( window->winId(), 777, MOD_WIN, VK_HOME ) ) {
    34. qDebug() << "FaceApp::SetupEventFilter says: RegisterHotKey HOME =" << VK_HOME;
    35. }
    36. if ( RegisterHotKey( window->winId(), 778, MOD_WIN, VK_END ) ) {
    37. qDebug() << "FaceApp::SetupEventFilter says: RegisterHotKey END =" << VK_END;
    38. }
    39.  
    40. if (evtdis != NULL) {
    41. qDebug() << "FaceApp::SetupEventFilter says: EventDispatcher found!";
    42. }
    43.  
    44. }
    To copy to clipboard, switch view to plain text mode 


    Main:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. FaceApp a(argc, argv);
    4.  
    5. //
    6. // Create the Main Window and DeskTop and Exec!
    7. //
    8. MyClass w;
    9. a.SetupEventFilter(&w);
    10.  
    11. QDesktopWidget desktop;
    12. w.move(desktop.screenGeometry().width()/2-w.width()/2, 10);
    13. w.show();
    14. qApp->exec();
    15.  
    16. return 0;
    17. }
    To copy to clipboard, switch view to plain text mode 

    When I run my program, the HotKey events do arrive fine. If I minimize my main-window, they still do. After starting another program, like Outlook, the HotKeys still make it through. However, when I start the game and press the HotKeys, nothing arrives any more.

    The Help of winEventFilter suggests I use the QAbstractEventDispatcher to receive system wide keystrokes. As you can see I have tried it, but don't know how to proceed. Calling the instance(), I can. But the what? Where do I put the code for receiving the events?

    Any help is appreciated!

  2. #2
    Join Date
    Apr 2010
    Posts
    11
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Receive HotKey events with QAbstractEventDispatcher?

    Well Guys and Girls

    Thanks, but No Thanks! Nobody has a clue? No problemo, I fixed it myself...
    If you need to get keyboard-input, no matter what the status of your application or window?: use DirectInput!
    This helped me on the way: http://www.directxtutorial.com/Tutor...put/dx9E1.aspx

  3. The following user says thank you to V4Friend for this useful post:

    Zlatomir (31st May 2010)

Similar Threads

  1. Replies: 3
    Last Post: 31st August 2009, 23:50
  2. How to register a global hotkey?
    By Fazer in forum Qt Programming
    Replies: 1
    Last Post: 17th July 2009, 13:55
  3. systemwide hotkey
    By Screeze in forum Newbie
    Replies: 9
    Last Post: 16th July 2009, 13:43
  4. How to realize the hotKey function?
    By cspp in forum Qt Programming
    Replies: 1
    Last Post: 1st July 2009, 12:12
  5. Setting Hotkey Shortcuts
    By VireX in forum Newbie
    Replies: 8
    Last Post: 4th April 2007, 23:22

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.