1# in command prompt, type "pip install pynput" to install pynput.
2from pynput.keyboard import Key, Controller
3
4keyboard = Controller()
5key = "a"
6
7keyboard.press(key)
8keyboard.release(key)
1import pyautogui
2
3# Holds down the alt key
4pyautogui.keyDown("alt")
5
6# Presses the tab key once
7pyautogui.press("tab")
8
9# Lets go of the alt key
10pyautogui.keyUp("alt")
1pip install keyboard
2
3import keyboard
4
5keyboard.press_and_release('shift+s, space')
6
7keyboard.write('The quick brown fox jumps over the lazy dog.')
8
9keyboard.add_hotkey('ctrl+shift+a', print, args=('triggered', 'hotkey'))
10
11# Press PAGE UP then PAGE DOWN to type "foobar".
12keyboard.add_hotkey('page up, page down', lambda: keyboard.write('foobar'))
13
14# Blocks until you press esc.
15keyboard.wait('esc')
16
17# Record events until 'esc' is pressed.
18recorded = keyboard.record(until='esc')
19# Then replay back at three times the speed.
20keyboard.play(recorded, speed_factor=3)
21
22# Type @@ then press space to replace with abbreviation.
23keyboard.add_abbreviation('@@', 'my.long.email@example.com')
24
25# Block forever, like `while True`.
26keyboard.wait()