macbook禁用键盘,如何以编程方式启用/禁用Mac内置键盘

I use command:

sudo kextunload /System/Library/Extensions/AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext

sudo kextload /System/Library/Extensions/AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext

to disable/enable mac build-in keyboard manually. It seems to unload/load driver for build-in keyboard and works fine.

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

The first task is simple, just use KextManager API will do me favor.

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

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??

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值