key — autopy module for working with the keyboard

This module contains various functions for controlling the keyboard.

Functions

key.toggle(key, down_or_up, [modifiers])

Holds down the given key or keycode if down_or_up is True, or releases it if not. Integer keycodes and modifiers should be taken from module constants (e.g., key.K_DELETE or key.MOD_META). If the given key is a character, it is automatically converted to a keycode corresponding to the current keyboard layout.

To hold down more than one modifier at a time, bitwise-OR them, e.g.:

toggle('a', True, key.MOD_SHIFT | key.MOD_ALT)
key.type_string(string, wpm=0)

Attempts to simulate typing a string at the given WPM, or as fast as possible if the WPM is 0.

key.tap(key, [modifiers])

Convenience wrapper around toggle() that holds down and then releases the given key and modifiers.

Constants

The following is an exhaustive list of constants used by this module in order to input non-printable keys across platforms. Most should be self-explanatory.

key.K_F1
key.K_F2
key.K_F3
key.K_F4
key.K_F5
key.K_F6
key.K_F7
key.K_F8
key.K_F9
key.K_LEFT
key.K_CONTROL
key.K_RIGHT
key.K_DOWN
key.K_END
key.K_UP
key.K_PAGEUP
key.MOD_CONTROL

Control key modifier.

key.K_ALT
key.MOD_META

Equivalent to the command key modifier on Mac OS X, the Windows key modifier on Windows, or the meta key modifiers on X11.

key.K_RETURN
key.MOD_NONE

Null modifier (meaning none are to be pressed).

key.MOD_ALT

Alt key modifier.

key.MOD_SHIFT

Shift key modifier.

key.K_PAGEDOWN
key.K_DELETE
key.K_HOME
key.K_ESCAPE
key.K_BACKSPACE
key.K_META
key.K_CAPSLOCK
key.K_SHIFT
key.K_F12
key.K_F10
key.K_F11