[Development] Windows plugin customisation: QWindowsKeyMapper

Henry Skoglund henry at tungware.se
Tue Aug 2 00:36:22 CEST 2022


On 2022-08-02 00:07, Laszlo Papp wrote:
> #include <QAbstractNativeEventFilter>
> #include <QApplication>
>
> #include <iostream>
>
> class MyMSGEventFilter : public QAbstractNativeEventFilter
> {
> public:
>     bool nativeEventFilter(const QByteArray &eventType, 
> [[maybe_unused]] void *message, long *) override
>     {
>
>         std::cout << eventType.toStdString() << std::endl;
> #ifdef Q_OS_WIN
>         if (eventType == "windows_generic_MSG") {
>             MSG *msg = static_cast<MSG *>(message);
>         } else if (eventType == "windows_dispatcher_MSG") {
>             MSG *msg = static_cast<MSG *>(message);
>         }
> #endif
>         return false;
>     }
> };
>
> int main(int argc, char *argv[])
> {
>     QApplication app(argc, argv);
>     MyMSGEventFilter filterObject;
>     app.installNativeEventFilter(&filterObject);
>     return app.exec();
> }
>

Hi, it works fine on Windows, but without a (hidden) window on the 
desktop you're doomed to receiving *very few* message. I.e. no HWND 
(that's why for example the DDE server creates a hidden window on the 
desktop). So easiest workaround is to add say a QWidget window:
...
     QApplication app(argc, argv);
     MyMSGEventFilter filterObject;
     app.installNativeEventFilter(&filterObject);
     MainWindow w;
     w.show(); // you can hide it now
     return app.exec();
...
BTW, I couldn't get it to compile on MSVC 2019 Qt 6.3.1 
("MyMsgEventFilter: cannot instantiate abstract class") but on MSVC 2019 
5.15.2 it works fine.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20220802/2e90ab51/attachment.htm>


More information about the Development mailing list