Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

zmagi

macrumors newbie
Original poster
Nov 29, 2018
9
0
Using Xcode 4.6.3 (4H1503)

- (BOOL)acceptsFirstResponder {
return YES;
}
-(void)keyDown: (NSEvent *)theEvent
{
if ([[theEvent characters] isEqualToString: @"f"]) {
NSLog(@"###");
}
}
 
There is nothing wrong with that code. Can you post your whole project? Something else is causing the problem.
 
The NSEvent is not firing and the functions for drag does not even respond on file drag and drop.
 

Attachments

  • eHandler.zip
    32.4 KB · Views: 337
ApplicationDelegate is not a subclass of NSResponder, you may implement keyDown: method in it, but it will not get invoked when you press keys.

Even in a small app you want to use a controller subclass instead of dumping functionality in the app delegate.

So, you need to create a controller/subview and place it in your window and do the key handling there.

See if you can find the book 'Cocoa Programming for OS X' by Aaron Hillegass
There is a chapter on the keyboard events. I've attached the example project for your review.
 

Attachments

  • TypingTutor.zip
    125.4 KB · Views: 330
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.