本文介绍了检测按下哪个键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何知道在Cocoa应用程序中按哪个键(我知道每个键都有一个相关的号码)?
How do I tell which key was pressed in a Cocoa Application (I know each key has an associated number)? In my case, I want to log the key to the console.
这是我的代码:
- (BOOL)acceptsFirstResponder {
return YES;
}
-(void)keyUp:(NSEvent*)event {
NSLog(@"Key %@", event);
}
推荐答案
http://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/Reference/Reference.html =nofollow> NSEvent
方法,或。
Use the NSEvent
methods keyCode
, characters
or charactersIgnoringModifiers
.
- (void)keyUp:(NSEvent *)event {
NSLog(@"Characters: %@", [event characters]);
NSLog(@"KeyCode: %hu", [event keyCode]);
}
这篇关于检测按下哪个键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!