Solution 1:

Sometimes the keyboard gets stuck. I found that rapidly pressing the shift, alt, and ctl keys will eventually unwedge them. Try about 6 or 7 good presses on each in rapid succession, eg shift shift shift shift shift alt alt alt alt

This is often enough to wake the keyboard to the proper state.

You might find another symtom is that you can't click mouse-button 1, you always get the context menu following the mouse around. This is a cure for that issue too.

Solution 2:

Assuming that the problem is with software, try the following :

  1. Fully patch Windows using Windows Update, including optional items (except Bing etc.)
  2. Use sfc /scannow to verify system integrity
  3. In Control Panel -> Device Manager, open Keyboards, delete your keyboard device and reboot (might need to use the power button)
  4. In Control Panel -> Region and Language, in the Keyboards and Languages tab, click Change keyboards.. and verify that you are using the correct keyboard. (Have you got more than one?)
  5. Boot into Safe mode and check whether the problem disappears. If it does, then an installed product is causing the problem.
    Use the System Configuration utility, General tab, click Selective startup and clear the Load startup items check box. On the Services tab, click the Hide all Microsoft services check box and click Disable all. OK out and restart the computer.
    If the problem still does not occur, turn on Services back in binary search mode until you find the guilty one.