문제

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

도움이 되었습니까?

해결책

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.

다른 팁

UCKeyTranslate().

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top