Contains routines for dealing with the keyboard.


  • pygame.key.set_repeat([delay, interval]) -> None
  • - change the keyboard repeat
  • pygame.key.get_pressed() -> tuple of bools
  • - get the pressed state for all keys
  • pygame.key.name(int) -> string
  • - get the name of a key
  • pygame.key.get_mods() -> int
  • - get current state of modifier keys
  • pygame.key.set_mods(int) -> None
  • - set the state of the modifier keys
  • pygame.key.get_focused() -> bool
  • - state of keyboard focus


    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. The default values for delay and interval are 500 and 30.


    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)


    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'.


    pygame.key.get_mods() -> int

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


    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.


    pygame.key.get_focused() -> bool

    Returns true when the application has the keyboard input focus.