inputs.Input

class inputs.Input

This class holds methods for accessing the state of the keyboard.

static pressed(key: str) inputs.ButtonState

Use this to query if specific key on the keyboard is being pressed. The key must be a str of length 1 and alphanumeric.

Note: If you want to share your script, consider listening to a transmitter key instead of directly querying the keyboard because some players might want to use your script in VR where they don’t have a keyboard.

Note

While this function works well for determining if a button is being held down during the frame that it is queried, quick presses might be missed between queries. In order to check for all button presses since the last query, use an stream().

static stream(key: str) streams.Stream[inputs.ButtonState]

Returns a stream of ButtonState’s corresponding to every key press and release that has occured since creation of the stream. To process all button events for a key follow this example.

from inputs import *
from time import sleep

input_stream_b = Input.stream("b")

while True:
    for event in input_stream_b:
        if event == ButtonState.DOWN:
            print("pressed b")
        elif event == ButtonState.UP:
            print("released b")

    sleep(.1)

The format for key can be found here.

Note: The stream only contains changes in button state. If the key had been held down since the last time the stream was checked, the stream will not contain ButtonState.DOWN. It will be empty because the key’s state hasn’t changed.

Note: If you want to share your script, consider listening to a transmitter key instead of directly querying the keyboard because some players might want to use your script in VR where they don’t have a keyboard.