Subscribe to Mac OS keypress event
Hi,
I'm trying basically to detect a keypress when my qt applikation is not in focus.
Is this even possible just using Qt?
I found this example:
https://doc.qt.io/qt-5/qabstractnati...r.html#details
But this doesn't seem to work, getting compile errors.
I would be very grateful if anyone in here could help me out :)
Re: Subscribe to Mac OS keypress event
Quote:
Originally Posted by
felli
I would be very grateful if anyone in here could help me out :)
Your link does not point at a complete program and we cannot see your code, compilation errors, or what platform(s) you are targeting so it is difficult to help there.
I do not know exactly what can and cannot be seen through these native event interfaces on the various p[latforms.
I suspect that you will not see every keypress on Windows but there are separate hooks you could try to use (see SetWindowsHookEx).
3 Attachment(s)
Re: Subscribe to Mac OS keypress event
Hi Chrisw67,
Thank you for you reply. The link was all that I could find unfortunately.
Please see the images below to see the project setup and compile errors.
.pro
Attachment 13627
.h
Attachment 13628
.mm
Attachment 13629
I'm developing on macOS Big Sur, the target platforms are Mac OS and windows 10.
Any help would very appreciated :)
<code>
/Volumes/Data/qt/nativeEvent/mycocoaeventfilter.mm:4: error: use of undeclared identifier 'CocoaNativeEventFilter'
../nativeEvent/mycocoaeventfilter.mm:4:6: error: use of undeclared identifier 'CocoaNativeEventFilter'
bool CocoaNativeEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *)
^
</code>
Re: Subscribe to Mac OS keypress event
Your code should be implementing MyCocoaEventFilter::nativeEventFilter() (declared in your header file) not CocoaNativeEventFilter::nativeEventFilter() (declared nowhere).
Re: Subscribe to Mac OS keypress event
thanks for the feedback ChrisW67. I thought maybe the CocoaNativeEventFilter::nativeEventFilter() was implemented <Appkit.h>, updated that and getting other compile errors now...
But my main question is how I can detect keypress events when my application is not in focus, is this possible with Qt?
thank you
Re: Subscribe to Mac OS keypress event
Quote:
Originally Posted by
felli
But my main question is how I can detect key press events when my application is not in focus, is this possible with Qt?
It is not really a Qt question: Qt deals with the key presses the operating system sends it when it has focus. The question is whether the OS gives you a way to intercept key presses regardless of where they would naturally flow.
NSEvent addGlobalMonitorForEvents() looks promising to turn on a capture:
https://developer.apple.com/document...nitorforevents
Exactly how you access this in your C++ code is not something I am familiar with although I expect that the resulting events should be seen in the Qt event filter.
Re: Subscribe to Mac OS keypress event
Quote:
Originally Posted by
ChrisW67
It is not really a Qt question: Qt deals with the key presses the operating system sends it when it has focus. The question is whether the OS gives you a way to intercept key presses regardless of where they would naturally flow.
NSEvent addGlobalMonitorForEvents() looks promising to turn on a capture:
https://developer.apple.com/document...nitorforevents
Exactly how you access this in your C++ code is not something I am familiar with although I expect that the resulting events should be seen in the Qt event filter.
Thank you ChrisW67, just the answer I needed. I will look into that. :)