Question

Is there a cocoa / carbon equivalent to the VkKeyScan and ToUnicode functions present on windows for translating between virtual scan codes and a unicode string? I would also like to perform this conversion vice versa (going from a char to a scan code).

Was it helpful?

Solution

I'm not sure there is, sadly. CGEvent and NSEvent (which aren't toll-free bridged, but NSEvent can convert back and forth) are the standard containers for events including key presses and as a result can convert from device-dependent scan codes to unicode string sequences but there seems to be no way to go in the other direction — from a unicode character to the required sequence of device-dependent key presses.

There's a brief comment underneath CGEventCreateKeyboardEvent that:

All keystrokes needed to generate a character must be entered, including modifier keys. For example, to produce a 'Z', the SHIFT key must be down, the 'z' key must go down, and then the SHIFT and 'z' key must be released:

But the sequence shown then has hardcoded and unexplained constants for the shift and z keys.

OTHER TIPS

UCKeyTranslate().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top