I used to use
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.