Before anything else
Unplug the keyboard, or shut down and disconnect a laptop and remove the battery if it is removable. Cleaning a powered keyboard risks both a short and a great many accidental keystrokes.
Take a photograph of the layout before removing any keycaps. It is much easier than working out afterwards where the punctuation goes.
Routine cleaning
- Turn the keyboard upside down and tap it firmly. This removes more than most people expect.
- Compressed air in short bursts at a shallow angle, working in one direction so debris leaves rather than migrating.
- A soft brush between the caps for the dust that air does not shift.
- A cloth very lightly dampened with isopropyl alcohol for the caps themselves. Dampen the cloth, never the keyboard.
Deeper cleaning on a mechanical keyboard
Keycaps on a mechanical keyboard pull straight off with a wire puller, and can be washed in warm water with a little washing-up liquid. Let them dry completely, which takes longer than it looks; trapped water inside a cap will find its way onto the switch.
With the caps off, compressed air and a brush reach the plate. Do not soak the board itself, and keep liquid away from the controller and any exposed connectors.
Switches themselves can be cleaned with contact cleaner made for electronics, applied very sparingly. Anything that leaves a residue, including household cleaners and general lubricants, will make the problem worse within weeks.
After a spill
Disconnect immediately and turn the keyboard upside down to drain. Speed matters more than technique here.
Water on a membrane keyboard is often survivable if it dries fully before power returns, and full drying takes a day or two, not an hour. Anything sugary or alcoholic is much worse, because it leaves a conductive, sticky residue as it dries.
On a laptop, a spill reaches components below the keyboard, and the correct move is to power down, disconnect and stop. A laptop that has taken a sugary drink is a professional repair, not a cleaning job.
Do not use a hairdryer on a wet keyboard. Heat warps keycaps and plastic clips, and pushes liquid further into the assembly.
Then test it
Once everything is dry and reconnected, run through every key in the keyboard tester. Cleaning occasionally frees one key and disturbs another, especially if keycaps were removed and reseated, so a full pass is worth the minute it takes.