pygame documentation | || Home || Help Contents || || pygame || cdrom || constants || display || draw || event || || font || image || joystick || key || mixer || mixer_music || || mouse || movie || sndarray || surfarray || time || transform || || CD || Channel || Clock || Font || Joystick || Movie || || Rect || Sound || Surface || || color || cursors || sprite ||

## pygame.key

Contains routines for dealing with the keyboard. All keyboard events can be retreived through the pygame.event module. With the key module, you can get the current state of the keyboard, as well as set the rate of keyboard repeating and lookup names of keysyms.

get_focused | - state of keyboard focus
get_mods | - get current state of modifier keys
get_pressed | - get the pressed state for all keys
name | - get the name of a key
set_mods | - set the state of the modifier keys
set_repeat | - change the keyboard repeat

get_focused
`pygame.key.get_focused() -> bool`

Returns true when the application has the keyboard input focus.

get_mods
`pygame.key.get_mods() -> int`

Returns a bitwise combination of the pressed state for all modifier keys (KMOD_LSHIFT, etc).

get_pressed
`pygame.key.get_pressed() -> tuple of bools`

This gives you a big tuple with the pressed state for all keys. You index the sequence using the keysym constant (K_SPACE, etc)

name
`pygame.key.name(int) -> string`

This will provide you with the keyboard name for a keysym. For example 'pygame.key.name(K_SPACE)' will return 'space'.

set_mods
`pygame.key.set_mods(int) -> None`

Allows you to control the internal state of the modifier keys. Pass an interger built from using the bitwise-or (|) of all the modifier keys you want to be treated as pressed.

set_repeat
`pygame.key.set_repeat([delay, interval]) -> None`

When the keyboard repeat is enabled, you will receive multiple KEYDOWN events when the user holds a key. You can control the repeat timing with the delay and interval values. If no arguments are passed, keyboard repeat will be disabled.
Good values for delay and interval are 500 and 30.
Delay is the amount of milliseconds before the first repeated KEYDOWN event is received. The interval is the amount of milliseconds for each repeated KEYDOWN event after that.