keyboard module for python 3 code example
Example 1: module to read keyboard
import keyboard
while True:
try:
if keyboard.is_pressed('q'):
print('You Pressed A Key!')
break
except:
break
Example 2: python library to control keyboard
from pynput.keyboard import Key, Controller
keyboard = Controller()
keyboard.press(Key.space)
keyboard.release(Key.space)
keyboard.press('a')
keyboard.release('a')
keyboard.press('A')
keyboard.release('A')
with keyboard.pressed(Key.shift):
keyboard.press('a')
keyboard.release('a')
keyboard.type('Hello World')