[Interest] Key_Cancel on Macintosh
john at wavemetrics.com
Tue Mar 20 21:09:13 CET 2012
On 20-Mar-2012, at 10:53 AM, Nikos Chantziaras wrote:
> Maybe this is relevant:
OK- that was a good lead. It seems that at that point the Cmd-period key event *IS* available. Here is my code:
In my subclass of QApplication:
bool IgorAppObject::macEventFilter(EventHandlerCallRef caller, EventRef event)
if (WMNSEventIsCmdPeriod(reinterpret_cast<void *>(event)))
In a .mm (objective C++) file:
NSEvent * nsevent = reinterpret_cast<NSEvent *>(event);
if ([nsevent type] == NSKeyUp) // presumably, if we see the key up it was preceded by a key down. Action should take place on key up.
std::cout << "NSEvent keydown event" << std::endl;
if ([nsevent modifierFlags] & NSCommandKeyMask)
NSString * chars = [nsevent charactersIgnoringModifiers];
return [chars characterAtIndex:0] == 0x2E; // Unicode encoding for period
The header containing the prototype for this function declares it to be extern "C". It is my understanding that that is required because Objective C++ mangles names differently than regular C++.
In addition to the above, I have regular QApplication::notify event filter looking for QKeyEvents that match Qt::Key_Cancel. That will provide the same functionality on platforms where Qt allows this access (empirically, Windows works this way).
Seems like since QApplication::macEventFilter() can see the relevant key events, it would be possible for Qt on Cocoa/Macintosh could just Do the Right Thing. But maybe not...
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Interest