Skip to content

Instantly share code, notes, and snippets.

Created February 20, 2012 12:34
What would you like to do?
Disable Mac OS X Keyboard (built-in only)
# Unload the keyboard so I can use my external keyboard
# and not worry about accidentally pressing buttons on
# the built-in. This may not be a problem for you but, you
# should see my desk sometimes (Oh no!!) ;-)
sudo kextunload /System/Library/Extensions/AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext/
Copy link

How to reload the kb?
sude kextload ?

Copy link

ptim commented Oct 27, 2013

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

(apparently! )

Copy link

john2x commented Dec 20, 2013

Does this still work for you on OS X Mavericks 10.9.1? It used to work for me before, but now I'm getting:

(kernel) Can't unload kext; classes have instances:
(kernel)     Kext class AppleUSBTCKeyboard has 1 instance.
Failed to unload - (libkern/kext) kext is in use or retained (cannot unload).

Copy link

I can' too
mine 10.9.5

Copy link

Despite the error, the internal keyboard seems disabled after the command.

os version 10.9.5

Copy link

I get the same error, but my keyboard is still enabled. OSX 10.10.2. Below is what the error says. Any help is appreciated.

(kernel) Kext not found for unload request.
Failed to unload - (libkern/kext) not found.

Copy link

Great work. Even though I still get the error, it works beautifully. Thank you. Is there a way to make a button out of this snippet? I use this at least once a day since my built-in keyboard has a mysterious shortage.

Copy link

for the ones looking for a way to disable the internal keyboard because you have a external one attached you can use this

also i tested the code about on OSX 10.11 and the unload works but i cannot load the kernel extension back and it only works if I reboot my computer

Copy link

ghost commented Apr 26, 2016

@arthurnn: Kudos to you!

Copy link

xyoun commented May 29, 2016

@arthurnn: awesome!

Copy link


Running this code on 10.11.3 crashed my mac. Just turned off and gave me the "something went wrong with your mac error" before restarting twice, and turning back on fine (with they keyboard enabled)

Looks like this solution doesn't work anymore.

Copy link

It used to work for me on Sierra. After I upgraded my OS to catalina, It stopped working. It gives me this error.

(kernel) Can't remove kext; services failed to terminate - 0xe00002c7.
Failed to unload - (iokit/common) unsupported function.

Copy link

I'm getting the same error as @rahul1990gupta

Copy link

Im avin te same issue, did anyone ind a soution to tis

Copy link

orvn commented Apr 7, 2021

  • Unload native keyboard: sudo kextunload -v 5 /System/Library/Extensions/AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext/
  • Reload native keyboard: sudo kextload -v 5 /System/Library/Extensions/AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext/

This does work on new versions of MacOS, but only when System Integrity Protection (SIP) is not affecting the context. SIP was introduced in El Capitan and got some upgrades in Mojave, so all newer MacOS will have this enabled: csrutil status

  • On El Capitan, Sierra and High Sierra, the kernel extension changes will throw an error due to some perms being protected, but the keyboard disabling does work
  • On Mojave, Catalina, Big Sur (and beyond), SIP protections won't even let a sudoer see, so the kextload finds nothing to unload

if you're on Mojave and above, running csrutil disable would "fix" the issue, but there are three caveats:

  1. SIP can't be disabled from the active OS instance itself, so the easiest solution is to boot from the recovery partition (cmd + r on boot) and run csrutil disable from there
  2. You must re-enable (via kextload) your built-in keyboard, or use a non-bluetooth keyboard, if you want to enter recovery mode at a later date, after disabling your keyboard with kextunload
  3. You are disabling MacOS's native protections for system-level directories, which technically would allow a 3rd party service to inject malicious code in a number of ways. Technically the app would need sudo permissions first to do that though. This is easy enough to protect and manage on a *nix server somewhere because you (should) have protections in place and a strict policy on who can su or sudo and when. But on an os with a GUI, with applications being closed, opened, installed, etc. constantly, it's not so easy to ensure something doesn't slip in.


  • Is there a way to limit SIP's strictness without reboot/recovery (like selinux config)? The answer is a soft "no" per the official docs. But there is an interesting output of System Integrity Protection status: enabled (Custom Configuration). This could suggest that it may be possible to selectively disable SIP features and set a custom config, but no suggestion on how this could be done is exposed in the docs. If someone knows more about this, lmk (/usr/bin/csrutil is a binary in mach-o format by the way)
  • How do 3rd parties like Karabiner-Elements accomplish disabling the keyboard? Perhaps they don't even need to touch the kernel extensions. It was implemented in this issue, v0.90.63, but I can't find a release with that tag so I don't see the commit. Searching through the codebase doesn't show anything too obvious re: kext. Any insight on that would be helpful too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment