Input_Engine

Use this page to discover keyboard, mouse, and MIDI devices, configure PDJE_Input_Module, and forward queued native events through an InputLine. Transport, lifetime, and native source boundaries are collected at the end.

Availability

The input and judge wrappers are build- and platform-conditional. Apple builds currently disable the input wrapper by default. Other supported builds expose PDJE_Input_Module and InputLine when PDJE_GODOT_ENABLE_INPUT_WRAPPER is enabled.

Current native backends are:

  • Windows Raw Input through a subprocess and IPC transport, reported as rawinput-ipc.

  • Linux evdev, with a Wayland-aware route when host/window context is needed.

  • MIDI as a separate stream configured alongside standard input.

Do not assume the input classes exist in every exported plugin. Verify the platform build and extension registration first.

Godot Classes

  • PDJE_Input_Module is a Node that owns native input discovery, configuration, runtime start, and shutdown.

  • InputLine is a Node that receives the native data line and converts current keyboard, mouse, and MIDI events into Godot signals.

Initialization And Device Selection

The required order is initialize, discover, select, configure, attach an InputLine, then run.

The example assumes this scene tree; both extension classes are custom Node types and the names match the $… paths used below:

Gameplay (Node with your script)
├── PDJE_Input_Module (PDJE_Input_Module)
└── InputLine (InputLine)

Connect InputLine signals to the gameplay script in the editor or from GDScript. InitializeInputLine(input_line) injects producer-owned native state into that existing node; it does not create or add the node for you.

@onready var input: PDJE_Input_Module = $PDJE_Input_Module
@onready var input_line: InputLine = $InputLine

func start_input() -> bool:
    if not input.Init():
        push_error("PDJE input initialization failed")
        return false

    var selected_standard: Array = []
    for device in input.GetDevs():
        if device["type"] == "KEYBOARD":
            selected_standard.push_back(device)

    var selected_midi: Array = input.GetMIDIDevs()
    if not input.Config(selected_standard, selected_midi):
        push_error("PDJE input configuration failed")
        return false

    input.InitializeInputLine(input_line)
    if not input.Run():
        push_error("PDJE input loop failed to start")
        return false

    print(input.GetCurrentInputBackend())
    return true

InitWithOptions(use_internal_window) is available when the Linux/Wayland path must allow PDJE to create an internal window. Prefer Init() unless that platform integration specifically requires the option.

Standard device dictionaries returned by GetDevs() contain:

Key

Meaning

device_specific_id

Native backend identifier.

name

Device display name.

type

KEYBOARD or MOUSE.

GetMIDIDevs() returns MIDI port names. Pass only selected names back to Config().

Emit Input Signals

InputLine does not emit automatically. Each emit_input_signal() call invokes Receive() for the keyboard/mouse transport, forwards that received batch, swaps the MIDI double buffer, and forwards that completed MIDI batch. Signal emission is deferred through Godot. Poll from _process(), _physics_process(), or a timer appropriate for your game; one call processes only the events available in that poll cycle.

func _process(_delta: float) -> void:
    input_line.emit_input_signal()

Connect the signals before starting gameplay:

func _ready() -> void:
    input_line.pdje_input_keyboard_signal.connect(_on_keyboard)
    input_line.pdje_input_mouse_signal.connect(_on_mouse)
    input_line.pdje_midi_input_signal.connect(_on_midi)

func _on_keyboard(
        device_id,
        device_name,
        microsecond_string,
        keyboard_key,
        is_pressed) -> void:
    print(device_id, device_name, microsecond_string, keyboard_key, is_pressed)

func _on_midi(
        port_name,
        input_type,
        channel,
        position,
        value,
        microsecond_string) -> void:
    print(port_name, input_type, channel, position, value, microsecond_string)

Signal contracts:

Signal

Arguments

pdje_input_keyboard_signal

device_id, device_name, microsecond_string, keyboard_key, is_pressed.

pdje_input_mouse_signal

device_id, device_name, microsecond_string, L_btn, R_btn, wheel_btn, side_btn, ex_btn, is_wheel_YAxis, wheel_move, mouse_axis_type, x, and y.

pdje_midi_input_signal

port_name, input_type, channel, position, value, microsecond_string.

Timestamps are decimal microsecond strings copied from the native high-resolution clock. Keyboard keys are bound InputLine enum values. Mouse button fields use -1 for down, 1 for up, and 0 for no transition in that parsed event. is_wheel_YAxis distinguishes vertical from horizontal wheel input; mouse_axis_type is REL, ABS, VIRTUAL_DESKTOP_ABS, or ERROR. Current MIDI type strings are NOTE_ON, NOTE_OFF, PITCH_BEND, CONTROL_CHANGE, AFTERTOUCH, and POLY_PRESSURE; channel, position, and value retain the integers produced by the native MIDI parser. value is raw event data such as velocity, pressure, controller value, or bend value according to input_type. A Judge rail_id is mapping state configured separately through DeviceAdd()/MIDI_DeviceAdd() and is not part of this raw signal.

State And Shutdown

GetState() reports DEVICE_CONFIG_STATE, INPUT_LOOP_READY, INPUT_LOOP_RUNNING, or DEAD. Stop capture explicitly:

func stop_input() -> void:
    input.Kill()

After Kill() or module reconstruction, configure again and call InitializeInputLine() with a newly acquired data line before polling.

Judge Integration

The current judge startup contract expects the input data line to contain a non-null standard-input arena. Even for MIDI rails, configure at least one keyboard or mouse device when using Judge_Engine.

Pass the configured PDJE_Input_Module to PDJE_Judge_Module.AddDataLines(input, core). Do not pass InputLine; it is the signal adapter for game code, while Judge consumes the module’s native data line. InputLine exposes six MIDI event types, but the current Judge wrapper can rail-map only NOTE_ON, NOTE_OFF, and POLY_PRESSURE; the other MIDI signals remain available to game code but are not accepted by MIDI_DeviceAdd().

Common Failures

  • Empty GetDevs() can indicate backend visibility or Linux input-permission problems.

  • emit_input_signal() before InitializeInputLine() logs an error and emits nothing.

  • An empty MIDI list means no matching ports were visible during discovery.

  • Run() before successful Config() does not establish a valid runtime.

  • Reusing an old InputLine after module teardown can reference invalid native storage.

Contributor Transport And Lifetime Model

The native PDJE_Input surface owns two independent lanes in PDJE_INPUT_DATA_LINE:

  • input_arena transports standard keyboard/mouse events. Native consumers call Receive() before reading the current event vector.

  • midi_datas is an atomic double buffer for current MIDI events.

The wrapper’s InputLine converts both lanes into copied Godot values. It must not expose the native pointers directly. Producer teardown invalidates the data line, and event timestamps are part of the synchronized high-resolution clock used by judge.

Primary source anchors:

Native symbol lookup:

class PDJE_Input

Input device manager.

Searches for connected devices and pairs them with the engine.

struct PDJE_INPUT_DATA_LINE
enum PDJE_INPUT_STATE

Values:

enumerator DEVICE_CONFIG_STATE
enumerator INPUT_LOOP_READY
enumerator INPUT_LOOP_RUNNING
enumerator DEAD