Search code examples
macoscocoakey-bindingsnsresponder

Is it possible to override the user KeyBindings with app-specific ones on a mac?


The user specific keyBindings .dict file is found in: ~/Library/KeyBindings/

How can you (as the developer) tell AppKit to look in another directory (app specific) for another bindings file for your specific application. This does not need to override the user specific one as it could be for functionality other than text manipulation.

This could be useful for the following reason:

  1. Changing keyBindings for your app without messing with the users settings for the rest of their system (in particular where your objects are not neccesarily text input objects)
  2. Adding additional action methods not found in NSResponder

Quoting from the Cocoa Event Handling Developer Guide (page 68). Emphasis is mine.

It can pass the event to Cocoa’s text input management system by invoking the NSResponder method interpretKeyEvents:. The input management system checks the pressed key against entries in all relevant key-binding dictionaries and, if there is a match, sends a doCommandBySelector: message back to the view. Otherwise, it sends an insertText: message back to the view, and the view implements this method to extract and display the text.


Solution

  • I don't believe it's possible. I think the bit about "all relevant key-binding dictionaries" is just referring to /System/Library/Frameworks/AppKit.framework/Resources/StandardKeyBinding.dict and ~/Library/KeyBindings/DefaultKeyBinding.dict.