How can I detect that the Shift key has been pressed?

前端 未结 7 1077
甜味超标
甜味超标 2020-12-10 00:37

I have a NSView subclass and I would like it to react when the user presses the ⇧ Shift key. However, -[NSView keyDown:] (which I curren

7条回答
  •  独厮守ぢ
    2020-12-10 01:24

    From the Cocoa event handling guide:

    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.

    The documentation for NSResponder also states the following:

    flagsChanged:

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

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

提交回复
热议问题