iDevGames Forums
Capturing Arrow Key Press - Printable Version

+- iDevGames Forums (
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Capturing Arrow Key Press (/thread-4939.html)

Capturing Arrow Key Press - robmcq - Oct 6, 2005 09:13 AM

Does anyone know what the structure is for the NSEvent class? I want to capture arrow input for my application. I know that this calls the keyDown and keyUp methods but I don't know anything about the NSEvent class that is passed into these functions. Any help is appriciated.


Capturing Arrow Key Press - seven - Oct 6, 2005 09:23 AM

Try this from apple's site.

Look in the constants section under keys.

Capturing Arrow Key Press - blobbo - Oct 6, 2005 09:40 AM

There's a lot of info on that already posted. Try searching.


- Use an array of keys to store their states (up, down)
- Operate based on those states. For instance, if you have a ship that's shooting, only shoot if the space bar state is down, and so on.

Capturing Arrow Key Press - Taxxodium - Oct 6, 2005 09:45 AM

try [event charactersIgnoringModifiers] which returns an NSString.

event is an NSEvent that you get from the keyDown method

Capturing Arrow Key Press - Cochrane - Oct 6, 2005 01:22 PM

Use the keyCode method, which returns an integer. There's an old, but still correct table somewhere on that shows what keys map to what key codes. Unfortunately, it's extremely hard to find, so if you can't find it, use an NSLog to show the codes you get when pressing the keys and then use them.

Edit: I found it here. I know it's old, but it worked for me.

Capturing Arrow Key Press - codemattic - Oct 7, 2005 01:19 AM

int keyCharacter = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
if (keyCharacter == NSUpArrowFunctionKey) .... ;