Domanda

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).

È stato utile?

Soluzione

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.

Altri suggerimenti

UCKeyTranslate().

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top