Ant*_*nio 6 c macos cocoa keyboard-shortcuts objective-c
我有个问题.我的Mac上有两个键盘布局,因为在与不同的人通信时我必须键入两种不同的语言.我使用键盘快捷键Cmd+Space从一种布局(语言)切换到另一种布局.
我想知道我是否可以在Cmd+Space按下时运行自定义脚本?我知道有一个名为Punto Switcher的应用程序可以做到这一点.
我的想法是更改键盘突出显示级别以指示当前语言.
问题是在哪里可以找到API

来自@Anoop Vaidya的LED亮度指针的整洁指针 - 看起来很有趣!
输入方法更改时,系统会发送通知.
首先,声明一个接收通知的函数:
void theKeyboardChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
NSLog(@"Keyboard/input method changed.");
}
Run Code Online (Sandbox Code Playgroud)
然后注册更改通知:
CFNotificationCenterAddObserver(CFNotificationCenterGetDistributedCenter(),
myContextInfo, theKeyboardChanged,
kTISNotifySelectedKeyboardInputSourceChanged, NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
Run Code Online (Sandbox Code Playgroud)
我发现了 Amit Singh 的博客,他在未记录的 API 中给出了想法,他使用了 C,为此,你肯定可以从中找到某种帮助。
或者您可以尝试使用这些代码:
UInt64 lightInsideGetLEDBrightness(){
kern_return_t kr = 0;
IOItemCount scalarInputCount = 1;
IOItemCount scalarOutputCount = 1;
UInt64 in_unknown = 0, out_brightness;
kr = IOConnectCallScalarMethod(dataPort, kGetLEDBrightnessID, &in_unknown, scalarInputCount, &out_brightness, &scalarOutputCount);
return out_brightness;
}
Run Code Online (Sandbox Code Playgroud)