如何使用目标c检测击键? [英] How do i detect keystrokes using objective c?

查看:134
本文介绍了如何使用目标c检测击键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想知道,我如何去检测不同的键击,然后检测什么键已经按我试图使用这个
- (void)keyDown:(NSEvent *)event
,但似乎没有得到任何结果。我也有一个搜索,但没有找到任何东西。我猜我可能需要在界面构建器中设置一些东西来检测击键?
我还认为它与所选择的内容有关,如果它的一个文本字段有东西。

Just wondering, how I go about detecting different keystrokes, and then detecting what key has been pressed I tried using this, -(void)keyDown:(NSEvent *)event but didnt seem to get any results. I've also had a search around but didn't find anything. I'm guessing I may have to set up something in interface builder to detect keystrokes? I also think that it has something to do with what is selected, if its a text field something.

推荐答案

keyDown:方法只被调用某些视图,它的子视图我想。如果您需要应用程式的所有按键操作,请检查 NSEvent 类方法:

keyDown: method is called only for certain view and it's subviews I think. If you need all keystrokes for your app - check NSEvent class method:

+ (id)addLocalMonitorForEventsMatchingMask:(NSEventMask)mask 
                                   handler:(NSEvent* (^)(NSEvent*))block

$ b b

阅读Xcode文档。我猜你是雪豹。

Read upon in it Xcode documentation. I presume you're on snow leopard.

这篇关于如何使用目标c检测击键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆