Only use external keyboard when laptop is open [duplicate]

Is it possible to completely disable the built-in keyboard on a MacBook? No input should be possible from that keyboard when I connect an external keyboard. This is sort of possible with the trackpad and the mouse, is there an option (or indeed a hack!) to do the same with the built-in hardware?


  • Install Karabiner

  • Choose your external keyboards on Devices > Advanced.

    enter image description here

  • Check the corresponding box

Source


From Googling around, I found this page. It suggests that you unload a AppleUSBTCKeyboard.kext to disable keyboard:

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

This will prompt you for your password and then give some errors, but it does disable the built in keyboard (tested on my ML 10.8.2)

To re-enable the builtin keyboard, load the kext file again:

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

BTW, I noticed that this immediately prints all that was typed on the builtin keyboard, so be ready for this (in Terminal this should probably just output some text).

For newer versions on MacOS / alternative solution:

List loaded kexts for keyboard

kextstat | grep Keyboard

It's going to output something like:

81    0 0xffffff7f833c5000 0xb000     0xb000     com.apple.driver.AppleHIDKeyboard (208) 96DDE905-9D31-38A9-96B7-FB28573587C8 <43 6 5 3>

com.apple.driver.AppleHIDKeyboard is loaded kext identifier.

If you want to plug-in Apple Magic Keyboard / some other Bluetooth keyboard, turn it off first. Then follow the instruction below.

To disable keyboard:

sudo kextunload -b com.apple.driver.AppleHIDKeyboard

To enable it back:

sudo kextload -b com.apple.driver.AppleHIDKeyboard

There is a little utility called Keyboard Cleaner and it seems to work fine for me on 10.10.5. You run the program and only cmd + q stay functional to then quit it.

http://jan.prima.de/~jan/plok/archives/48-Keyboard-Cleaner.html