Step 1
Take all the applicable steps in this support article. That's the starting point for any further efforts to solve the problem.
Step 2
If you're running OS X 10.8.5 or earlier, from the menu bar select
▹ System Preferences... ▹ Accessibility
If the checkbox at the bottom marked
Enable access for assistive devices
is checked, uncheck it and test.
If you're running OS X 10.9 or later, select
▹ System Preferences... ▹ Security & Privacy ▹ Privacy ▹ Accessibility
If any applications are listed on the right and have a checked box next to them, uncheck all the boxes and test. You may first have to click the padlock icon in the lower left corner of the window and authenticate as an administrator to unlock the settings.
Step 3
Disconnect all wired peripherals except those needed to boot, if any. Be sure to disconnect all USB hubs. If you use a keyboard or mouse plugged into a hub, plug the devices directly into a built-in USB port and remove the hub. Test.
Step 4
If you have more than one user account, you must be logged in as an administrator for this step.
Launch the Console application in any of the following ways:
☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
☞ Open LaunchPad. Click Utilities, then Console in the icon grid.
In the Console window, look under the heading DIAGNOSTIC AND USAGE INFORMATION on the left for Diagnostic and Usage Messages. If you don't see that heading, select
View ▹ Show Log List
from the menu bar. In the search box in the window's toolbar, enter "powerd" (without the quotes.) Select the last few messages that appear, if any, and copy them to the Clipboard by pressing the key combination command-C. Paste into a reply to this message (command-V).