From charlesreid1

Notes

Link: https://github.com/boppreh/keyboard

Fork that adds support for Mac keyboards (very useful set of 0x commands for particular keys): https://github.com/willwade/PyUserInput/blob/master/pykeyboard/mac.py

The keyboard library allows you to control the keyboard directly from Python.

Installing

pip install keyboard

This raised some problem with Quartz, so I ran:

$ pip install pyobjc
$ pip install pyobjc-framework-Quartz # should be redundant, but just in case...

Using

A short example of what you can do with the library:

import keyboard

keyboard.press_and_release('shift+s, space')

keyboard.write('The quick brown fox jumps over the lazy dog.')

# Press PAGE UP then PAGE DOWN to type "foobar".
keyboard.add_hotkey('page up, page down', lambda: keyboard.write('foobar'))

# Blocks until you press esc.
keyboard.wait('esc')

# Record events until 'esc' is pressed.
recorded = keyboard.record(until='esc')
# Then replay back at three times the speed.
keyboard.play(recorded, speed_factor=3)

# Type @@ then press space to replace with abbreviation.
keyboard.add_abbreviation('@@', 'my.long.email@example.com')
# Block forever.
keyboard.wait()

Flags