开发者

How to change the Mac OS X Keyboard Layout programmatically?

开发者 https://www.devze.com 2023-01-09 03:36 出处:网络
My Qt app supports changing input language on Linux and Windows. I want to add support for changing the input language in Mac OSX, too.

My Qt app supports changing input language on Linux and Windows. I want to add support for changing the input language in Mac OSX, too.

开发者_开发技巧

Unfortunately I don't have any information about the Mac SDK. (My first and last work with OS X was compiling Qt and compiling my app!)

I googling this problem and found that I need to use Text Input Source Services and also I found these codes:

TISInputSourceRef isref;
isref = TISCopyCurrentKeyboardInputSource();
CFDataRef uchr = (CFDataRef)TISGetInputSourceProperty(isref, kTISPropertyUnicodeKeyLayoutData);

UCKeyboardLayout * keyLayoutPtr=(UCKeyboardLayout*)CFDataGetBytePtr(uchr);

Is keyLayoutPtr a pointer for current keyboard layout?

If the answer to the above question is "yes", then what should I compare with keyLayoutPtr?

In other words, how can I check if the current keyboard layout is (for example) "English"? (Or something like LANG_ENGLISH in Win API or us in XLib.)


I think you'd pass isref to TISGetInputSourceProperty, using the key kTISPropertyInputSourceLanguages, and check whether the first language code in the array is "en" or something like that. I don't know if it will return just "en" or "en-US" etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消