Maybe Windows' Sticky Keys function jumps into focus, or another window that opens in the background. I would first make sure that the game window doesn't lose focus and disable Sticky Keys. You can do this by pressing the keys WINDOWS LOGO + I under Windows 10, then clicking 'Ease of Access' -> 'Keyboard' and deactivate this function. (In older Windows versions it should work similar.)