开发者

keyUp/keyDown problems in Cocoa

I'm programming an app that will be a basic video game, but the keyUp:(NSEvent ) and keyDown:(NSEvent) methods are failing to execute.

This is my code:

-(void)keyUp:(NSEvent*)event {
    NSLog(@"Key %@", event);
}

-(void)keyDown:(NSEvent*)event {   
    switch( [event keyCode] ) {
        case 126:
        case 125:
        case 124: 
        case 123:       
   NSLog(@"Arrow key pressed!");
   break;
        default:
   NSLog(@"Key %@", event);
   break;
    }
}

I made sure it was in a subclass of NSResponder (although it is in NSOpenGLVie开发者_运维技巧w, could that be affecting it?) and other then that I don't see any problem. Any help is greatly appriciated. Thanks :)


Did you implement the NSResponder method acceptsFirstResponder to return YES?

- (BOOL)acceptsFirstResponder {
    return YES;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜