Try starting up in "Safe Mode" and see if the same thing happens in there. If it does not, then you have a virus, malware, or bad program on the computer that is giving you trouble and will need to be removed.
If, however, it happens in "Safe Mode" as well, then you likely have a hardware issue. If that is the case, then I would try connecting an external keyboard and see if it happens or not with that. If it doesn't happen, then the attached keyboard may well need replacing.
How to enter "Safe Mode" when booting the computer.
In Windows 8 and 10...
As your computer restarts, press F8 (possibly a few times) to enter "Safe Mode"
a. Press the "F4" key to Enable "Safe Mode".
(The computer will then start in "Safe Mode" with a minimal...