如何以编程方式更改Mac OS X键盘布局? [英] How to change the Mac OS X Keyboard Layout programmatically?

查看:88
本文介绍了如何以编程方式更改Mac OS X键盘布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Qt应用程序支持在Linux和Windows上更改输入语言.我也想添加对在Mac OSX中更改输入语言的支持.

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.

很遗憾,我没有有关Mac SDK的任何信息.(我在OS X上的第一个也是最后一个工作是编译Qt和编译我的应用程序!)

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

keyLayoutPtr 是否是当前键盘布局的指针?

Is keyLayoutPtr a pointer for current keyboard layout?

如果上述问题的答案为是",那么我应该与 keyLayoutPtr 比较什么?

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

换句话说,如何检查当前的键盘布局是否为英语"?(或者像 Win API 中的 LANG_ENGLISH 或 XLib 中的 us 之类的东西.)

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

推荐答案

我认为您会使用 kTISPropertyInputSourceLanguages键将 isref 传递给 TISGetInputSourceProperty .code>,然后检查数组中的第一个语言代码是"en"还是类似的名称.我不知道它是否只会返回"en"或"en-US"等.

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.

这篇关于如何以编程方式更改Mac OS X键盘布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆