Keyboard shortcut to lock the keyboard, without locking the screen?

You can use KeyboardCleanTool (made by the developer of BetterTouchTool).

It opens the application window with a button you have to press in order to lock/unlock the keyboard.

Download it from BetterTouchTool.net

Screenshot of KeyboardCleanTool on macOS 10.12


There's no way to turn off a keyboard via shortcut because you would have no way to turn it back on. The best method to achieve what you are looking for is to disconnect the keyboard.

Wired/USB Keyboards

To do that, you should use a USB with a "disconnect" or a "power switch" to turn it on/off like the Sabrent 4 Port Switch. I recommended this for a different question in which the user needed to "reset" the USB bus to redetect their device; this will work perfectly for you.

enter image description here

When you want to "lock" your keyboard, just turn off the port. Turning it back on will automatically reconnect it.

What about wireless?

Turn it off. When you turn it back on, it will automatically reconnect.