[cocoa keyboardInput]

Joined
Nov 26, 2006
Messages
18
Reaction score
1
Points
3
I am stuck right now on how to capture the arrow keys.I could just use the key codes but the documentation says they are hardware specific.

According to the docs.
Note that some function keys are handled at a lower level and are never seen by your application...

The Arrow keys are considered function keys from what I gather because,

if ([anEvent modifierFlags] & NSFunctionKeyMask ) {
}

will ring TRUE when the arrow keys create an event. I could use a clue as to how I can then test for the constants "NSUpArrowFunctionKey" and his partners?
Every test I have tried so far ring TRUE.
 
OP
T
Joined
Nov 26, 2006
Messages
18
Reaction score
1
Points
3
Not to bump the post but:
Just in case anyone is interested. I have found one way. You can load the StandardKeyBinding.dict dictionary file and check the key-value using the return from [anEvent characters] as the key.

Code:
- (void)keyDown:(NSEvent *)anEvent
{
	if ([anEvent modifierFlags] & NSFunctionKeyMask) {
		if ([[keyBindings objectForKey:[anEvent characters]] isEqual:@"moveLeft:"]) {
			NSLog(@"leftArrow"); 
		}
		if ([[keyBindings objectForKey:[anEvent characters]] isEqual:@"moveRight:"]) {
			NSLog(@"rightArrow");
		}
		if ([[keyBindings objectForKey:[anEvent characters]] isEqual:@"moveDown:"]) {
			NSLog(@"downArrow");
		}
		if ([[keyBindings objectForKey:[anEvent characters]] isEqual:@"moveUp:"]) {
			NSLog(@"upArrow");
		}
	}
}

If anyone knows a better way, for that matter any other way, please let me know.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top