3

I used to use kextload and kextunload to unlock/lock my keyboard. However, the actual kernel extension changes between MacBook models, and that can have unexpected results.

For example, if the kext is AppleUSBTCKeyboard, both unloading and loading work fine. However, if the kext is AppleHIDKeyboard (e.g. MacBook Air), unloading works but loading again does not. This means kextunload -bundle-id com.apple.driver.AppleHIDKeyboard will disable the keyboard, but then it cannot be reenabled with kextload and the machine has to be rebooted.

There are some apps that are still able to do it, like KeyboardCleanTool. I’d prefer a CLI way of doing it, though. If possible (but won’t be picky) using only tools that come with macOS, or an open-source one.

Bonus points if there’s also a way to lock the trackpad, but that is less important.

  • Just to be clear, you just want to lock your keyboard and/or trackpad while leaving your screen on. Correct? – Allan Jan 6 '17 at 14:30
  • @Allan Yes, that is correct. But is there a way to do it with turning off the screen (but not the machine or logging out/locking)? – user137369 Jan 6 '17 at 14:34
  • 1
    Just out of curiosity...if you disable the keyboard, how would you re-enable it when you are ready to work again? After all, the keyboard will be disabled. – Allan Jan 6 '17 at 14:53
  • With a timer, as I used to: kextunload … && sleep 30 && kextload …. I only need temporary locking, for keyboard cleaning. One could also do it with a script to double click (if not locking the trackpad). – user137369 Jan 6 '17 at 14:56
  • When I clean my keyboard (Apple BT keyboard), I just turn it off, clean it and turn it back on. If it's a USB, I just disconnect, clean and reconnect. Is this not a viable solution? – Allan Jan 6 '17 at 20:30
-1

One possibility could be to use ControllerMate.

You would have to create a Driver Configuration and map all of the keys to None. Then there are multiple ways to enable/disable the custom Driver Configuration, but unfortunately CLI is currently not an option.

But CM is very customizable and I'm sure you could come up with something. For example, using the logic blocks, you could have it disable when you have held down Z for 2 seconds, then hold down P and click the mouse. Using a delay timer block to wait for 30 seconds but then only re-enable if holding the left shift key down and scrolling the mouse up/down.

Another similar utility that might work is Karabiner-Elements. It is a complete rewrite of his wonderful Karabiner app which broke hard with macOS Sierra. It is still in the early development stages but it might have the functionality you need.

  • 3
    OP already has a non-CLI way to do this, KeyboardCleanTool, as they stated in the question. – Timothy Mueller-Harder Jan 6 '17 at 19:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .