KeyDown event

Discussion in 'Mac Programming' started by Gandolfmatt, Jul 21, 2008.

  1. Gandolfmatt macrumors member

    Joined:
    Jul 18, 2008
    #1
    I'm currently playing with OpenGl in the cocoa framework of Xcode and I'm trying to get my app to detect if a arrow key is pressed. I've researched for hours today with hardly any luck, I have found other examples that worked and tried to duplicate their code into my project, but when I press a arrow key the computer beeps and nothing happens.

    Anyone know a solution or could give me instructions of how to do it?


    -Gandolf
     
  2. MrFusion macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #2
    Doesn't something like this work?

    Code:
    -(void)keyDown:(NSEvent *)theEvent{
     printf("You pressed a key. Thank you, try again.");
    }
    
    Also, is your view configured to be firstresponder? Because if something else responds to the keydown before it gets to your code, you won't see the event.
     

Share This Page