I'm trying to simulate a key being held down for a specific amount of time using python. I first tried using the keyboard module to accomplish this like so:
import time
import keyboard
keyboard.press('space')
time.sleep(5)
keyboard.release('space')
This block of code will correctly press the space key but not hold it down. It taps space and then instantly releases it before time.sleep(5) is called. The space key is pressed and released once, the program waits 5 seconds, then does nothing and exits. I also tried using the pynput module to accomplish this task like so:
import time
from pynput.keyboard import Key, Controller
keyboard = Controller()
keyboard.press(Key.space)
time.sleep(5)
keyboard.release(Key.space)
The same exact issue arises. Space is pressed and then instantly released instead of being held down. I also tried using the AHK module:
import time
from ahk import AHK
ahk = AHK()
ahk.key_down('Space')
time.sleep(5)
ahk.key_up('Space')
None of these modules have worked for me. I've tested all of them by opening up a blank notepad and then running the script.