如何检测到已按下Shift键? [英] How can I detect that the Shift key has been pressed?

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

问题描述

我有一个 NSView 子类,我想它会反应,当用户按下⇧Shift 键。但是,当按下修饰键时,不会调用 - [NSView keyDown:] (我目前覆盖)。

I have a NSView subclass and I would like it to react when the user presses the ⇧ Shift key. However, -[NSView keyDown:] (which I currently override) isn't called when modifier keys alone are pressed.

如何在按下Shift键时收到通知?

How can I be notified when the Shift key has been pressed?

推荐答案

p>

From the Cocoa event handling guide:


flagsChanged:方法可用于检测修改键的按下,而不同时按下任何其他键。例如,如果用户自己按下Option键,您的响应程序对象可以在其实现的flagsChanged中检测到这一点:

The flagsChanged: method can be useful for detecting the pressing of modifier keys without any other key being pressed simultaneously. For example, if the user presses the Option key by itself, your responder object can detect this in its implementation of flagsChanged:.

更多可以此处找到详细信息。

More details can be found here.

NSResponder 的文档还说明了以下内容:

The documentation for NSResponder also states the following:


flagsChanged:

flagsChanged:

通知接收者用户按下或释放了修饰键(Shift,Control等)。

Informs the receiver that the user has pressed or released a modifier key (Shift, Control, and so on).

- (void)flagsChanged:(NSEvent *)theEvent

-- (void)flagsChanged:(NSEvent *)theEvent

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

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