1from pynput.keyboard import Key, Controller
2
3keyboard = Controller()
4
5# Press and release space
6keyboard.press(Key.space)
7keyboard.release(Key.space)
8
9# Type a lower case A; this will work even if no key on the
10# physical keyboard is labelled 'A'
11keyboard.press('a')
12keyboard.release('a')
13
14# Type two upper case As
15keyboard.press('A')
16keyboard.release('A')
17with keyboard.pressed(Key.shift):
18 keyboard.press('a')
19 keyboard.release('a')
20
21# Press keys with hex, code in: https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
22keyboard.press(KeyCode.from_vk(0x5C))
23keyboard.press(KeyCode.from_vk(0x27))
24keyboard.release(KeyCode.from_vk(0x27))
25keyboard.release(KeyCode.from_vk(0x5C))
26
27# Type 'Hello World' using the shortcut type method
28keyboard.type('Hello World')