If it is doing it on both attached and external keyboards, then you may have a motherboard problem (which would need replacing) but before going that far, lets try and see if it is something on the laptop rather than hardware. Try starting up the device in "Safe Mode" and see if it happens in there. If it does, then you are going to have to have the hardware looked at. If it, however, doesn't do this in "Safe Mode", then you likely have a bad program, virus, malware, etc. on the laptop that needs to be removed.
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...