Reputation: 11039
Is it possible programatically change keyboard input anywhere , when the program is in tray? Example. When user type text in, say, Google Chrome then my program catch the key the user types, and change it to another symbol (in another language)?
A -> ❤
B -> 웃
C -> ✄
etc.
Is it possible? and if answer is YES, then how?
Upvotes: 0
Views: 415
Reputation: 96323
This sounds like a job for a custom keyboard layout.
After installing your keyboard layout, the user need only enable it in the “Language & Text” preference pane and then select it in the Input menu extra.
It's also possible to enable and select an input source (keyboard layouts being a kind of input source) programmatically.
Upvotes: 1
Reputation: 90521
You can use Quartz event taps to receive all key events first and modify them before allowing them to be processed (or substitute different events entirely). Note that the user will have to enable access by assistive devices in Universal Access preferences in order for event taps to see keyboard events.
You could create, install, and have the user select a custom keyboard layout. You can use the third-party Ukelele program to create and modify keyboard layouts. This doesn't involve code, necessarily. It's just a big state machine for translating key codes to characters.
You can probably accomplish something like this by implementing an input method, too. See the Input Method Kit.
Upvotes: 0
Reputation: 12782
You can do this a number of ways. You could capture NSEvent key events and change them. You could override keyDown: in your own view subclass. And more.
Read up on the Cocoa Text System first https://developer.apple.com/library/mac/documentation/TextFonts/Conceptual/CocoaTextArchitecture/Introduction/Introduction.html
Upvotes: 0