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# Type 'Hello World' using the shortcut type method
22keyboard.type('Hello World')
23