Have tried to set the energy savers to never let the computer sleep? Not ideal but if it worked at least you would be okay to keep typing. Also some Mac keyboards the power on key is also an immediate off key - any chance you are touching by accident?
apple support for OS X.
Preventing your computer from sleeping
You can prevent your computer from going to sleep if you need it to continue performing a task, such as burning a CD or DVD.
1. Choose Apple menu > System Preferences, and then click Energy Saver.
2. If necessary, click Show Details, then click Sleep.
3. Drag the slider that controls the computer's sleep to "Never."
When the computer finishes the task, you should change the settings in Energy Saver preferences so that your computer will go to sleep when it's not in use.