Eeeek! I just spilled my [insert favorite drink here] on my laptop/keyboard!
Sure wish Macs were not so vulnerable to this sort of accidental spillage. If it’s only water, you may have lucked out. Immediately unplug the computer. Yeah, just yank that cord out of the wall; you don’t want to risk electric shock, do you? Then flip the keyboard or laptop upside down so whatever flowed in can flow out again, as much as possible. (If it’s a laptop, this is a good time to pull the battery out too, so the computer is definitely OFF.) Use a dry tissue to mop up whatever comes out.
If it’s a desktop keyboard, and you spilled something other than water on it, here’s what to do. Disconnect the keyboard’s USB cable from the computer. Take it to the kitchen or bathroom sink and flush it out real good with warm water under the faucet. You want to try to flush out any sugary or oily residue, which can really yuck up the works. Shake it out well and then set it upside down on a shelf in a warm spot, and leave it for a week or two. Chances are good it will be just fine after that, once it has completely dried out.
When I was doing Mac Support at Goshen College, there were several “incidents” of spills on keyboards — sugary sodas or coffee with milk, etc. They were all USB desktop keyboards, not laptop keyboards. In every case, after the fresh water flush treatment in the bathroom sink — and sufficient drying time — every one of those keyboards survived and went back into service later.
Apple wireless keyboards are more common these days, and — for the record — I’ve never tried the flush technique on a wireless keyboard. If you’re gonna try it, be sure to pop out the battery first!
In most cases your keyboard will be ok after spillage, once it has completely dried out. But don’t start using it again until you’re sure all the moisture is gone.
Double eeek! Obviously you can’t use the flush technique on a laptop; there are other electronic components in there that may not survive being doused. If the spill was just water, you may still be lucky, but it can take a long time to drive out all the moisture. Turn the laptop upside down and shake it (careful, not too hard) to get as much of the liquid out. Then try setting the computer near a source of warm air (like a radiator), or if you have a hair dryer give it a five or ten minute blast (careful, not TOO hot!) while giving the keys a workout. As water dries, it can leave a mineral residue on a keyboard, preventing keys from closing a key-press contact. Keyboards are mechanical, so try wiggling the keys a bit (gently) to “rub off” mineral residue inside the keys. That might or might not work.
If the spill leaked beyond the keyboard and got onto the logic board, there are components there with unsoldered contacts where liquid could seep in and disrupt connections until it’s totally dried out. But the hard drive is probably fine — it’s in a sealed box.
I’ve heard of a rice technique that might be worth a try. (NOTE: I’ve never tried this myself.) Simply cover the keyboard with uncooked white rice for a few days to absorb moisture. The fatter the rice kernels the better; you don’t want any rice getting underneath the keys because that could interfere with key presses.
If the problems don’t clear up with continued attempts to dry the laptop out, then you’ll need to take your Mac to Apple. Maybe you’ll only need to get the keyboard replaced. Or maybe the logic board. If you do seek an Apple repair, it’s best to show up in person at your nearest Apple store. Be honest with them and describe exactly what happened, and what you’ve tried to do to fix it. Mac laptops (and iPhones and iPads) have sensors inside that detect exposure to water, and the Apple technicians will not appreciate it if you fib. But store employees have considerable leeway to provide a free fix if they can do it right then and there… provided you are completely honest with them.