I think the best way to do this is to teach him it's not good to stay on your keyboard.
With a child you would say "You can't do this" and he would understand. But animals doesn't understand portuguese english (I'm Brazilian XD), so that tatic of sprinkling some water on it is good.
Everytime he manages to do this, sprinkle water and take him out. Your cat will get upset and after some tries he will link the bad idea of "water in my face" with "keyboard", and that going on it is a bad idea; they won't try to do this anymore.
You can do this also with direct flashing light (2 flashes at most, please) and some simple words, like "No you can't". The words will get linked too, and after sometime you can try only to say "No you can't", and they will obbey.
I don't think that giving food or toys will help. They don't want food or toys, they want to sleep on that confortable thing that your keyboard is. And you need to tell them they shouldn't.
Of course that if you aren't giving them enough attention or food, they want food and attention, so you should be right it's not the problem, first of all.
After that... good luck =D
1
Cross-site duplicate: http://lifehacks.stackexchange.com/questions/9531/how-can-i-keep-my-cat-off-my-keyboard
– bwDraco – 2015-11-21T23:50:40.893I'm not completely sure this question has to do with superuser. I think it is a great question but needs to be moved. – RookieTEC9 – 2015-11-22T00:47:14.143
The solution,I believe, is to move the mouse away from the keyboard.Maybe that will take your cat's attention at something else other than keyboard(usually placed next to mouse). – Ivan Prodanov – 2009-08-22T18:55:26.803
https://www.thisiswhyimbroke.com/heated-keyboard-cat-bed/ – K7AAY – 2019-09-12T16:36:41.300
Just curious, how are they a motivating factor? – Troggy – 2009-08-22T19:24:26.027
18so...
cat < keyboard > floor
? (all together now: groan) – David Z – 2009-08-23T08:05:38.1332I use a laptop computer most of the time, and I keep it closed whenever I'm not using it. :) – Anderson Green – 2013-02-05T23:49:12.243