Mac: I find that the moments I want to clean my keyboard (or have just spilled coffee on it) are rarely the times when my computer is actually off. More often I decide to clean my keyboard when I have 12 open tabs and a half-written blog post in the works, and don't want to power down just to do a quick cleaning. Enter KeyboardClean Tool.
If you have a USB keyboard you can just unplug it for cleaning purposes, but if you use a wireless keyboard the only way to switch it off is by removing the batteries. KeyboardClean Tool is a free and tiny app locks down your keyboard until you click on the app's button with your mouse. This ensures you can clean a switched-on keyboard without accidentally deleting half your work or filling it with gibberish.
KeyboardClean was created by the same developer as Better Touch Tool, a great little app that adds lots of handy gestures to your mouse.