KeyboardInputQueue

Bases: InputQueue

Tracks the history of the keyboard input channels.

Example
keyboard_handler = KeyboardInputQueue()
if keyboard_handler.is_pressed(pygame.K_ESC):
    pygame.quit()
Source code in robingame/input/keyboard.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
class KeyboardInputQueue(InputQueue):
    """
    Tracks the history of the keyboard input channels.

    Example:
        ```
        keyboard_handler = KeyboardInputQueue()
        if keyboard_handler.is_pressed(pygame.K_ESC):
            pygame.quit()
        ```
    """

    def get_new_values(self) -> tuple[int]:
        scancode_wrapper = pygame.key.get_pressed()
        return tuple(scancode_wrapper[ii] for ii in range(len(scancode_wrapper)))