xxxxxxxxxx
#pip install keyboard
import keyboard
while True:
# Do your stuff
if keyboard.is_pressed("q"):
# Key was pressed
break
xxxxxxxxxx
if keyboard.is_pressed('q'): # if key 'q' is pressed
print('You Pressed A Key!')
break # finishing the loop
xxxxxxxxxx
if keyboard.is_pressed('q'): # if key 'q' is pressed
print('You Pressed A Key!')
break # finishing the loop
xxxxxxxxxx
# firsrt install pynput
# pip install pynput
from pynput.keyboard import Key, Controller
# Create a Controller object
keyboard = Controller()
# Simulate pressing the 'a' key
keyboard.press('a')
keyboard.release('a')
# Simulate pressing the 'enter' key
keyboard.press(Key.enter)
keyboard.release(Key.enter)