Within an implementation of a keyDown: method, a responder can extract the character data contained by the associated NSEvent object and insert it into displayed text or it can interpret the character data as a key or key combination that is either bound to a keyboard action or requests some application-specific behavior. IsARepeat-This method tells the responder whether the same key was pressed rapidly in succession. ModifierFlags-Using this method the responder can determine if any modifier keys were pressed. Note that both method names are plural because a keystroke can produce more than one character (for example, “à” is composed of ‘a’ and ‘`‘). The charactersIgnoringModifiers method ignores any modifier keystroke (except for Shift) when returning the character data. Some of the more useful NSEvent methods for key events are the following:Ĭharacters and charactersIgnoringModifiers-The responder can extract the Unicode character data associated with the event and insert it as text or interpret it as commands. As with mouse events, a responder object often wants to query the passed-in NSEvent object to find out more about the event and obtain the data it needs to handle it. A text object typically interprets the message as a request to insert text, while a drawing object might only be interested in a few keys, such as Delete and the arrow keys as commands to delete and move selected items. The object can handle the event in any way it sees fit. Most responder objects (such as custom views) handle key events by overriding the keyDown: method declared by NSResponder. See Overriding the keyDown: Method for more information.Īs with key event messages, a keyboard action message is passed up the responder chain if the first responder does not handle it. At this point, the key event could represent any one of the following things:Ī keyboard action, which is a key or key combination bound to an action-message selector in a key bindings dictionary (see Key Bindings).Īn application-specific command or action (one not using the key bindings dictionary)Ī character or characters to insert into text The responder object determines what the key event represents and handles it appropriately. If the event is neither of these, it dispatches it to the NSWindow object representing the key window, which in turn dispatches the event to the first responder in a keyDown: message. The global application object ( NSApp) first looks for key equivalents and then keyboard interface control commands and handles them specially (see The Path of Key Events for details). The delivery path of a key event varies according to whether the event represents a character, a key equivalent, a keyboard action, or a keyboard interface control command. If the first responder does not handle the event, it passes the event up the responder chain (see The Responder Chain). Most key events-that is, those representing characters to be inserted as text-are dispatched by the NSWindow object associated with the key window to the first responder. For example, if the user presses the Option key by itself, your responder object can detect this in its implementation of flagsChanged. The flagsChanged: method can be useful for detecting the pressing of modifier keys without any other key being pressed simultaneously.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |