1

I have an application that processes keystrokes via keyDown.

This works well so far, with the exception of two problems (I'll post/ask the other later).

The problem here is the Shift+Tab combo. I would like to process it myself, but as explained in the Mac OS keyboard event doc, it is used to move the focus forward.

I tried capturing it under

-(BOOL)performKeyEquivalent:(NSEvent *)nsevent
{

}

where I do get an event for it, returning TRUE or FALSE but it still does not appear in keyDown:

I also know about selectNextKeyView: but ideally I am looking for a way to get the system to pass the combination to keyDown: for normal handling (incidentally keyUp: is called correctly for it).

-(void)selectNextKeyView:(id)sender
{
    // shift+tabbed
}
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Terminality
  • 799
  • 6
  • 11

1 Answers1

0

Answering my own question:

I solved it by intercepting selectNextKeyView and selectPreviousKeyView and forwarding the [NSApp currentEvent] to my keyboard handler (the one that is called on keyDown: for all other keys)

-(void)selectNextKeyView:(id)sender
{
    // this is part of the keyboard handling.  Cocoa swallows ctrl+Tab and
    // calls sselectNextKeyView, so we create a matchin key event for the occasion
    NSEvent *nsevent= [NSApp currentEvent];
    [self handleKeyEvent:nsevent isRaw:FALSE isUp:FALSE];
}

-(void)selectPreviousKeyView:(id)sender
{
    // this is part of the keyboard handling.  Cocoa swallows ctrl+shift+Tab and
    // calls selectPreviousKeyView, so we create a matchin key event for the occasion
    NSEvent *nsevent= [NSApp currentEvent];
    [self handleKeyEvent:nsevent isRaw:FALSE isUp:FALSE];
}
Terminality
  • 799
  • 6
  • 11
  • This is not ideal because these methods could get called for other reasons, not just Shift+Tab. – Taylor Oct 18 '16 at 15:30
  • Plus, you should consider using some other key combination since users will be used to using Tab and Shift+Tab to navigate controls, and would be surprised that it doesn't work for your app. – Taylor Oct 18 '16 at 15:32