A.H Asghary
A.H Asghary

Reputation: 77

How to get Keyboard Layout in Mac With C++

i find below code that get keyboard layout but cant convert it to string :


TISInputSourceRef sourceRef = TISCopyCurrentKeyboardLayoutInputSource();

If you use CFShow(sourceRef); you can see keyboard layout but cant convert sourceRef.

How to get keyboardLayout in string ???

Upvotes: 3

Views: 943

Answers (1)

febeling
febeling

Reputation: 1474

I use this objc code:

#import <Carbon/Carbon.h>

TISInputSourceRef source = TISCopyCurrentKeyboardInputSource();
NSString *s = (__bridge NSString *)(TISGetInputSourceProperty(source, kTISPropertyInputSourceID));

You can probably also cast it to CFStringRef instead of an objc string.

Upvotes: 2

Related Questions