I am learning how to create programs using Cocoa. I am using a sample Apple application that records video from a webcam. I would like to start and stop the video by capturing a keystroke. I tried to override the keydown event, but I read that this is not possible in NSObject. How can I handle such events?
NSObject
The application class extends the class NSObject.
This is the code:
- (void)keyDown:(NSEvent *)event { NSLog(@"Hi there"); NSString *characters = [event characters]; if ([characters length]) { switch ([characters characterAtIndex:0]) { case NSUpArrowFunctionKey: NSLog(@"Key UP"); break; } } }
I tried to override the Keydown event, but I read that this is not possible in NSObject.
Correctly. The responder can only respond to events.
How can I handle this type of event?
. NSWindow NSWindowController . , .
Cocoa .
NSObject.
? , NSApplication - NSApplication.
PS: , MacOS?
Hillegass ( Apple), , , .
Cocoa - :
-, . - , ( ).
keyDown. , ( Safari Firefox, , ).
( Safari , ), , Guide. (, .)
, keyDown: , , . - keyDown:
, sendEvent:. sendEvent: , , , , .
NSWindow NSWindowController .
Similarly, you can subclass NSView and override its event handling methods.
What is a very good book to start learning MacOS programming?
Learning Objective-C on Mac from Dalrymple is very easy, covers enough bases, and moves fast enough to get you a little off the ground. It affects everything from Xcode and Interface Builder to OOP and Objective-C. Particularly useful for newbies (IMHO) are the source file organization and Foundation set-up chapters.
Good luck