If your keyboard is part of a laptop, I wouldn't do it. I would think that would help seal in the heat and pose a problem for the longevity of the keyboard.
As for regular keyboards, I think an actual keyboard cover would probably be best.
If you do spill something on your keyboard, assuming it's a modern USB device that can be unplugged without shutting the computer down first, unplug the keyboard right away. If it is wireless, remove the batteries. Turn it upside-down over paper towels and let the liquid come out. For best results, disassemble the keyboard and wash the parts. For the actual board, wash with distilled water or isopropyl alcohol. If you spilled soda, coffee, juice or anything that might be sticky, give it a good rinse. Check the keys to make sure any residue is gone. Let dry thoroughly before attempting to use it again.
My father has a habit of spilling coffee on his keyboards. I've saved a number of them. But, also, some have been cheap and haven't recovered. Fortunately, he's not ruined the temporary keyboards I've given him during drying periods.