如何以编程方式启用/禁用Mac内置键盘 [英] how to enable/disable mac build-in keyboard programmatically
问题描述
我使用命令:
sudo kextunload/System/Library/Extensions/AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext
sudo kextunload /System/Library/Extensions/AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext
sudo kextload/System/Library/Extensions/AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext
sudo kextload /System/Library/Extensions/AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext
手动禁用/启用mac内置键盘.似乎可以卸载/加载内置键盘驱动程序,并且工作正常.
to disable/enable mac build-in keyboard manually. It seems to unload/load driver for build-in keyboard and works fine.
那么如何在代码中完成该操作.我认为,我需要完成两项任务.
1.卸载/加载驱动程序
2.运行sudo命令
So how to do it in the code. In my opinion, I needed to do two tasks.
1. unload/load the driver
2. run sudo command
第一个任务很简单,只需使用 KextManager API会对我有所帮助.
The first task is simple, just use KextManager API will do me favor.
第二个,我发现Apple文档说,当您要运行 sudo 身份验证任务时,出于安全考虑,您应该使用类似以下内容的产品:
1.发射
2. SMJobless
3. XPC服务
4.等等...
将高权限任务抽象为作为启动过程运行的子帮助程序工具,并使用XPC服务在主应用程序和该帮助程序工具之间进行通信.
The second one, I found Apple documents say when you want to run sudo authentication task, with the security consideration, you should use something like:
1. launchd
2. SMJobless
3. XPC service
4. etc...
to abstract the high rights task to a sub helper tool run as a launchd process, and use XPC service to communication between main application and this helper tool.
我尝试了所有这些,并且辅助工具可以正常工作,但是当我使用
I tried all of these, and helper tool works fine, but when I use
KextManagerUnloadKextWithIdentifier(CFSTR("com.apple.driver.AppleUSBTCKeyboard"));
KextManagerUnloadKextWithIdentifier(CFSTR("com.apple.driver.AppleUSBTCKeyboard"));
帮助器工具中的
.它不起作用,内置键盘未正确禁用.
in the helper tool. It did not work, the build-in keyboard is not disabled properly.
我想念东西还是有另一种方法来做这项工作?
Do I miss something or there is another way to do the job??
推荐答案
当我重新启动Macbook时,它起作用了,所以这是解决此问题的正确方法.
如果您还有其他想法,请对其进行评论.
When I restarted my macbook, it worked... so it is a right way to solve this problem.
If you have another ideas, just comment it.
这篇关于如何以编程方式启用/禁用Mac内置键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!