4

I am creating one cocoa application having wizard like structure.

All dialogs are subclass of NSViewController. Currently I am not able get keyboard events such as keyDown and keyUp..

Please help me to solve this problem....

Thanks in advance....

Priya
  • 51
  • 1
  • 3

3 Answers3

4

Override keyDown: and keyUp: method.

-(void)keyUp:(NSEvent*)event
-(void)keyDown:(NSEvent*)event

and

- (BOOL)acceptsFirstResponder {
    return YES;
}

In subclass of NSViewController you should refer Cocoa Event-Handling Guide .

Parag Bafna
  • 22,812
  • 8
  • 71
  • 144
1

If you are trying to simply get an event for escape, use this instead:

override var acceptsFirstResponder: Bool {
    return true
}

override func cancelOperation(_ sender: Any?) {
    // The user pressed escape
}
Sam Soffes
  • 14,831
  • 9
  • 76
  • 80
0

Setting window to "Auto Recalculates View Loop" in Inteface Builder has worked for me.

Vaibhav Gade
  • 143
  • 9