Cocoa 中的 keyUp/keyDown 问题
我正在编写一个基本视频游戏的应用程序,但 keyUp:(NSEvent ) 和 keyDown:(NSEvent) 方法无法执行。
这是我的代码:
-(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;
}
}
我确保它位于 NSResponder 的子类中(尽管它位于 NSOpenGLView 中,但这会影响它吗?),除此之外我没有看到任何问题。非常感谢任何帮助。谢谢 :)
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 NSOpenGLView, could that be affecting it?) and other then that I don't see any problem. Any help is greatly appriciated. Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你是否实现了NSResponder方法acceptFirstResponder来返回YES?
Did you implement the NSResponder method acceptsFirstResponder to return YES?