2

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

pkamb
  • 33,281
  • 23
  • 160
  • 191
S. Razi
  • 378
  • 2
  • 8
  • Possible duplicate of [Change OSX keyboard layout("input source") programmatically via terminal or AppleScript?](https://stackoverflow.com/questions/23729704/change-osx-keyboard-layoutinput-source-programmatically-via-terminal-or-appl) – Bill Nov 17 '19 at 13:02

1 Answers1

1

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.

JWWalker
  • 22,385
  • 6
  • 55
  • 76