macoscocoakey-bindingsnsresponder

Standard mac key bindings behaving erratically


I am trying to use the standard mac keybindings (found in ~\Library\KeyBindings\DefaultKeyBinding.dict) to map to the action methods found in NSResponder. I am overriding these action methods in one of my custom classes to perform custom navigation between my UI elements.

In the keyBindings file both ^-p and map to the action method moveUp:

The confusing thing is that when I push the in my app the action method fires BUT when I push ^-p nothing happens (just a beep indicating that it couldn't find anything matching in the responder chain).


Solution

  • Subsequent testing revealed the following (performed a stack trace):

    I had NOT implemented a keyDown method anywhere so my action methods where not firing as regular action methods. What was happening is that the keyDown event was traveling up the responder chain to NSWindow where it was being handled in a way similar to Key Interface Control KIC.

    The first strange thing is that KIC is documented to happen before the keyDown events gets sent and this is effectively at the end of the keyDown event responder chain. The KIC is evidently not picking up its key bindings from the standard keybindings dictionary but is looking for its own keys - some of which must include arrow keys for navigation.

    The second strange thing is the KIC was looking to the implementation of the action method to know what to do with the arrow key press.

    This behaviour is undocumented to the best of my knowledge and is a confusing mix of KIC and action methods. But it is what it is.