inputs.TransmitterReference

class inputs.TransmitterReference(hand: Optional[Hand], id: int = 0)

Represents a specific transmitter. The target transmitter may be on the left or right hand, or it may be a custom keyboard transmitter. To set the state of a button on this transmitter, call press(). To read for the state of a transmitter, call stream().

press(key: Union[ButtonId, str], value: float = 1)

Use this to virtually press a key on this transmitter. It will stay pressed until you call this again with value 0.

If this transmitter represents a hand transmitter, supply key as a ButtonId. If instead it represents a custom (i.e. keyboard) transmitter, supply key as a str.

If the transmitter is not active, it will not drive any controllables until it is active.

The below example demonstrates how to toggle the up button on the left transmitter.

from inputs import *
from time import sleep

transmitter = TransmitterReference(Hand.LEFT)

while True:
    # press up on the left hand
    transmitter.press(ButtonId.UP,1)
    sleep(1)
    # release it
    transmitter.press(ButtonId.UP,0)
    sleep(1)
stream(key: Union[ButtonId, str]) Stream[float]

Returns a stream of input values from this transmitter for the key key.

The below example demonstrates how read from the stream of a left transmitter and the custom transmitter.

from inputs import *
from controllables import TextScreen

# get the output screen
screen = TextScreen()
screen.horizontal_alignment = TextScreen.HorizontalAlignment.LEFT

# here we get the 'x' button stream from the custom transmitter
x_stream = Transmitters.custom_transmitter().stream('x')
# here we get the up button stream from the left transmitter
up_stream = Transmitters.left_transmitter().stream(ButtonId.UP)

x_signal = 0
up_signal = 0
# in an infinite loop
while True:
    # we'll get get the last signal in the x stream
    for signal in x_stream:
        x_signal = signal

    # we'll get get the last signal in the up stream
    for signal in up_stream:
        up_signal = signal

    screen.text = f'x: {x_signal: 0.1f}\nup: {up_signal :0.1f}'