2

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.

Hannes Karppila
  • 969
  • 2
  • 13
  • 31
  • Does iOS not support another API for sending unicode characters? For example on windows you'd send a `WM_CHAR`/`WM_UNICHAR` instead of a `WM_KEYDOWN`/`WM_KEYUP` in this scenario. [`CGEventKeyboardSetUnicodeString`](https://developer.apple.com/documentation/coregraphics/1456028-cgeventkeyboardsetunicodestring?language=objc) looks like a likely candidate. – CodesInChaos Mar 10 '18 at 16:24

0 Answers0