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!