Ever needed to implement a 'Force Keyboard Layout' feature for your OSX application? Look no further!
This small library will handle saving the user's desired keyboard layout, as well as KVC-support so
you can bind the available layouts to a NSPopUpButton
Please note that this is my first attempt at a library. Comments and criticisms very much appreciated!
Only tested on 10.8, but should work for 10.7 at the very least.
- Add source files, either manually or with CocoaPods (once the Podfile has been added)
- Link Carbon.framework if you're doing it manually
In the preferences nib or where you want to create the NSPopUpButton
for users to pick what layout to force:
- Drag in an
NSObject
, set the class toCDOForceKeyboardLayoutController
- Drag in an
NSArrayController
, name itAvailable Keyboard Layouts Controller
or something similar - Drag the
NSPopUpButton
to your desired location - In the
NSArrayController
:- In the Bindings panel, Bind the
Content Array
to theForce Keyboard Layout Controller
, and set theModel Key Path
toself.availableKeyboardLayouts
- In the Attributes panel, set the
Class Name
in theObject Controller
section toCDOKeyboardLayout
- In the Bindings panel, Bind the
- In the
NSPopUpButton
Bindings panel:- Bind the
Content
toAvailable Keyboard Layouts Controller
- Bind the
Content Values
toAvailable Keyboard Layouts Controller
:- Set the
Model Key Path
tolabel
- Check the
Inserts Null Placeholder
box - Set the
Null Placeholder
to whatever value you desire
- Set the
- Bind the
Selected Object
toForce Keyboard Layout Controller
:- Set the
Model Key Path
toself.forceKeyboardLayout
- Set the
- Bind the
And that should be it! Let me know if you have difficulty with this. Please also refer to the Demo app that's within the project.
MIT. See LICENSE
for more details.