I have a Unicode representation of a key, e.g. "a", "!", "ä" or "€", and I want to find out what key code (sequence) is used to produce that character. The resulting virtual key code will be given to CGEventCreateKeyboardEvent
to simulate keyboard events.
The solution must be keyboard layout independent, e.g. sending "A" must work with any keyboard layout (e.g. Dvorak).
The solution will probably require using something like TISCopyCurrentKeyboardInputSource
, but that seems to be deprecated (and I couldn't get it to work either).
I'm using Rust and core_graphics
crate. Adding more crates isn't an issue. This Objective-C solution might be possible to adapt.