Skip to content

Ports

KeyIO

KeyIO(*, supress_input: bool = False)

Bases: MultiPort

Keyboard input/output port that combines KeyIn and KeyOut ports. Produces and sends KeyMsg objects.

Parameters:

  • supress_input (bool, default: False ) –

    Prevent the input events from being passed to the rest of the system

Warning

Use supress_input with caution! You'll lose the keyboard input unless you're proxying it to an output port.

is_opened

is_opened: bool

True if port is listening messages / ready to send messages

pressed_keys

pressed_keys: list[Key]

Currently pressed keys

subscribe

subscribe(
    type: None | Container[KeyEvent] | KeyEvent = None,
    shortcut: None | Container[str] | str = None,
) -> Callable

Decorator to subscribe a callable to all the wrapped inputs' messages.

Decorator without arguments subscribes a callable to all the input's messages.

Decorator with arguments subscribes a callable to the input's messages that match conditions set by arguments. It works the same way as message's matches method:

  1. If condition is None or omitted it matches anything.

  2. If condition equals the message's attribute value it matches the attribute.

  3. If condition is a container (list, tuple) and contains the message's attribute value, it matches the attribute.

Examples
  1. Calls function for all MIDI port's messages:
    @midi_input_instance.subscribe
    def function(msg: MidiMsg) -> None:
        pass
    
  2. Calls function for OSC messages from specific address:
    @osc_input_instance.subscribe(address='/live/song/get/track_data')
    def function(msg: OscMsg) -> None:
        pass
    
  3. Call object instance method for MIDI port's "note on" and "note off" messages:
    midi_input_instance.subscribe((MidiType.NOTE_ON, MidiType.NOTE_OFF))(object.method)
    

Returns:

  • Callable

    Subscribed callable.

send

send(msg: KeyMsg) -> None

Send the keyboard input.

Parameters:

  • msg (KeyMsg) –

    object to send

type_in

type_in(string_to_type: str) -> None

Type in the text as a keyboard

KeyIn

KeyIn(*, supress_input: bool = False)

Bases: Input

Keyboard input port. Produces KeyMsg objects.

Parameters:

  • supress_input (bool, default: False ) –

    Prevent the input events from being passed to the rest of the system

Warning

Use supress_input with caution! You'll lose the keyboard input unless you're proxying it to an output port.

is_opened

is_opened: bool

True if port is listening messages / ready to send messages

pressed_keys

pressed_keys: list[Key]

Currently pressed keys

subscribe

subscribe(
    type: None | Container[KeyEvent] | KeyEvent = None,
    shortcut: None | Container[str] | str = None,
) -> Callable

Decorator to subscribe a callable to the input's messages.

Decorator without arguments subscribes a callable to all the input's messages.

Decorator with arguments subscribes a callable to the input's messages that match conditions set by arguments. It works the same way as message's matches method:

  1. If condition is None or omitted it matches anything.

  2. If condition equals the message's attribute value it matches the attribute.

  3. If condition is a container (list, tuple) and contains the message's attribute value, it matches the attribute.

Examples
  1. Calls function for all MIDI port's messages:
    @midi_input_instance.subscribe
    def function(msg: MidiMsg) -> None:
        pass
    
  2. Calls function for OSC messages from specific address:
    @osc_input_instance.subscribe(address='/live/song/get/track_data')
    def function(msg: OscMsg) -> None:
        pass
    
  3. Call object instance method for MIDI port's "note on" and "note off" messages:
    midi_input_instance.subscribe((MidiType.NOTE_ON, MidiType.NOTE_OFF))(object.method)
    

Returns:

  • Callable

    Subscribed callable.

KeyOut

KeyOut()

Bases: Output

Keyboard output port. Sends KeyMsg objects.

is_opened

is_opened: bool

True if port is listening messages / ready to send messages

send

send(msg: KeyMsg) -> None

Send the keyboard input.

Parameters:

  • msg (KeyMsg) –

    object to send

type_in

type_in(string_to_type: str) -> None

Type in the text as a keyboard