Re: [Interest] Key_Cancel on Macintosh

2012-03-20 Thread John Weeks

On 20-Mar-2012, at 10:24 AM, Konstantin Tokarev wrote:

 On Windows, I can filter keypress events looking for Qt::Key_Cancel, which 
 is generated by pressing Ctrl+Break.The Macintosh equivalent is Cmd-period. 
 As far as I can make out, the Cocoa system catches that key combination and 
 sends some sort of cancel event instead of a key event.
 My question: is there a way to catch this in Qt on Macintosh?
 
 Try to catch it with event filter. If it fails you probably will need to 
 write custom ObjC code.

That was fast! Thanks!

In fact, my first attempt was an event filter. But on Macintosh, I get no key 
event when I press cmd-period.

I expect the Objective C code will be required (groan). I wonder if anyone has 
already written something already that they would be willing to share. I get 
confused by having all those brackets in the wrong places :)

-John

___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] Key_Cancel on Macintosh

2012-03-20 Thread Nikos Chantziaras
On 20/03/12 19:31, John Weeks wrote:

 On 20-Mar-2012, at 10:24 AM, Konstantin Tokarev wrote:

 On Windows, I can filter keypress events looking for Qt::Key_Cancel,
 which is generated by pressing Ctrl+Break.The Macintosh equivalent is
 Cmd-period. As far as I can make out, the Cocoa system catches that
 key combination and sends some sort of cancel event instead of a key
 event.
 My question: is there a way to catch this in Qt on Macintosh?

 Try to catch it with event filter. If it fails you probably will need
 to write custom ObjC code.

 That was fast! Thanks!

 In fact, my first attempt was an event filter. But on Macintosh, I get
 no key event when I press cmd-period.

Maybe this is relevant:

http://qt-project.org/doc/qt-4.8/qapplication.html#macEventFilter

___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] Key_Cancel on Macintosh

2012-03-20 Thread John Weeks

On 20-Mar-2012, at 10:53 AM, Nikos Chantziaras wrote:

 Maybe this is relevant:
 
 http://qt-project.org/doc/qt-4.8/qapplication.html#macEventFilter


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:

#ifdef MACIGOR
bool IgorAppObject::macEventFilter(EventHandlerCallRef caller, EventRef event)
{
if (WMNSEventIsCmdPeriod(reinterpret_castvoid *(event)))
emit cancelEvent();

return false;
}
#endif

In a .mm (objective C++) file:

bool
WMNSEventIsCmdPeriod(void *event)
{
NSEvent * nsevent = reinterpret_castNSEvent *(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
}
}
return false;
}

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...

-John Weeks

___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest