Mac Forums

Mac Forums (http://www.mac-forums.com/forums/)
-   OS X - Development and Darwin (http://www.mac-forums.com/forums/os-x-development-darwin/)
-   -   [cocoa keyboardInput] (http://www.mac-forums.com/forums/os-x-development-darwin/64356-cocoa-keyboardinput.html)

Three 06-01-2007 09:29 PM

[cocoa keyboardInput]
 
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.
Quote:

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.

Three 06-03-2007 10:28 AM

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.


All times are GMT -4. The time now is 04:29 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.