How to handle non-character keyboard events?
How to handle non-character keyboard events?
- Subject: How to handle non-character keyboard events?
- From: André Benassi <email@hidden>
- Date: Fri, 7 Dec 2001 09:51:38 -0600
I am trying to get my small program to recognize arrow key inputs from
the keyboard. I have the following method (kiped from Mike Beam's
wonderful article on O'Reilly):
- (void)keyDown:(NSEvent *)theEvent {
NSString *keyChar = [theEvent characters];
if ( [keyChar isEqualToString:@"c"] ) {
[path removeAllPoints];
[self setNeedsDisplay:YES];
}
}
- (BOOL)acceptsFirstResponder {
return YES;
}
I am trying to modify the code so it handles the Up arrow key,
NSUpArrowFunctionKey. I have tried replacing
[keyChar isEqualToString:@"c"]
with:
[keyChar isEqualToString:NSUpArrowFunctionKey]
[keyChar isEqual:NSUpArrowFunctionKey]
and:
NSString *theKey = NSUpArrowFunctionKey;
[keyChar isEqualToString:theKey]
3 questions:
Am I going about this the right way?
NSUpArrowFunctionKey is a (Unicode) unsigned short. How do I cast it to
a string? Do I need to?
Any help very appreciated from this newbie.
Andri Benassi
http://www.visi.com/~andre/