Source

pygame / doc / src / sdlkeyboard.xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE module SYSTEM "api.dtd">

<module name="pygame2.sdl.keyboard">
  <short>SDL keyboard I/O wrapper module</short>
  <desc>SDL keyboard I/O wrapper module</desc>

  <func name="enable_repeat">
    <call>enable_repeat (delay, interval) -> None</call>
    <desc>
      Enables or disables the keyboard repeat rate.

      Enables or disables the keyboard repeat rate. delay specifies how
      long a key must be pressed before the repeat begins. interval is
      the speed with which it repeats. delay and interval are expressed
      as milliseconds. Thus, after the initial delay has passed,
      repeated KEYDOWN events are sent through the event queue, using
      the specified interval.

      Setting delay to 0 will disable repeating completely.
    </desc>
  </func>
  <func name="enable_unicode">
    <call>enable_unicode ([enable]) -> bool</call>
    <desc>
      Enables or disables unicode input handling.

      Enables or disables unicode input handling. If the argument is
      omitted, the function will return the current unicode handling
      state.

      By default unicode handling is enabled and for keyboard events,
      the *unicode* member of the event will be filled with the
      corresponding unicode character.
    </desc>
  </func>
  <func name="get_key_name">
    <call>get_key_name (key) -> str</call>
    <desc>
      Get the descriptive name for a key constant.
    </desc>
  </func>
  <func name="get_mod_state">
    <call>get_mod_state () -> state</call>
    <desc>
      Returns the current state of the modifier keys (CTRL, ALT, etc.).

      Returns a single integer representing a bitmask of all the
      modifier keys being held. Using bitwise operators you can test if
      specific shift keys are pressed, the state of the capslock button,
      and more.

      The bitmask will consist of the various KMOD_* flags as specified
      in the constants.
    </desc>
    <example>
      ...
      import pygame2.sdl.keyboard as keyboard
      import pygame2.sdl.constants as constants
      ...
      
      # Check, whether any control ar alt key was pressed.
      if (keyboard.get_mod_state () &amp; (constants.KMOD_CTRL | constants.KMOD_ALT)) != 0:
          print ("A control or alt key is pressed")
      ...
    </example>
  </func>
  <func name="get_repeat">
    <call>get_repeat () -> delay, interval</call>
    <desc>
      Gets the currently set keyboard repeat delay and interval.
    </desc>
  </func>
  <func name="get_state">
    <call>get_state () -> dict</call>
    <desc>
      Gets the current keyboard state.

      Gets a dictionary with the current keyboard state. The keys of the
      dictionary are the key constants, the boolean values of the
      dictionary indicate, whether a certain key is pressed or not.
    </desc>
  </func>
  <func name="set_mod_state">
    <call>set_mod_state (mod) -> None</call>
    <desc>
      Sets the current modifier key state.

      Sets the current modifier key state. mod has to be a bitwise OR'd
      combination of the KMOD_* flags as they are specified in the
      constants.
    </desc>
    <example>
      ...
      import pygame2.sdl.keyboard as keyboard
      import pygame2.sdl.constants as constants
      ...
      
      # Enable numlock.
      keyboard.set_mod_state (constants.KMOD_NUM)
      ...
    </example>
  </func>
</module>