eve.aio.windows.console
Async console input primitives for Windows.
This module provides Windows console input support for TUI applications. It uses a background thread to read console input events and delivers them to the event loop via callbacks.
The console input reader supports:
- Key press/release events with virtual key codes and characters
- Mouse events — clicks, movement, scrolling
- Window resize events
- Focus gain/loss events
Example:
auto loop = EventLoop.create();
auto console = ConsoleInput.create();
console.onEvent = (ref ConsoleInput c, scope const(ConsoleInputEvent)[] events) {
foreach (ref evt; events) {
if (evt.type == ConsoleEventType.KEY && evt.key.keyDown) {
// Handle key press
}
}
};
console.start(loop);
loop.run();
console.stop();
console.dispose();Copyright
Types 8
Console input event types.
Represents the category of console input event received from Windows.
Key event data.
Contains information about a keyboard event including the key code, character produced, and modifier key state.
bool keyDown`true` for key press, `false` for key release.ushort repeatCountNumber of times the key was repeated.ushort virtualKeyCodeVirtual key code (VK_* constants).ushort virtualScanCodeHardware scan code.dchar characterUnicode character produced by the key press.uint controlKeyStateModifier key state (CTRL, ALT, SHIFT flags).Mouse event data.
Contains information about mouse position, button state, and event type.
short xX coordinate in console character cells.short yY coordinate in console character cells.uint buttonStateButton state flags.uint controlKeyStateModifier key state (CTRL, ALT, SHIFT flags).uint eventFlagsEvent flags indicating type of mouse event.Window resize event.
Contains the new console window dimensions in character cells.
short widthNew window width in character cells.short heightNew window height in character cells.Focus event.
Indicates whether the console window has gained or lost focus.
bool focused`true` when focus is gained, `false` when lost.Union of all console input event types.
This struct represents a single console input event, with a type discriminator and a union of event-specific data.
ConsoleEventType typeThe type of this event.Callback type for console input events.
Called when console input events are available. The events array is only valid for the duration of the callback.
/**
- Async console input reader for Windows.
- Provides non-blocking console input for TUI applications by using
- a background thread to read INPUT_RECORDs and delivering them via
- the event loop callback mechanism.
- The reader spawns a worker thread that blocks on
ReadConsoleInput - and signals the event loop when events are available. This allows
- the main thread to process console input alongside other async I/O.
void onEvent(ConsoleInputCallback callback) @property @trusted nothrowRegister a callback for console input events.ConsoleState state() @property const @trusted nothrow @nogcGet the current state of the console input reader.bool isRunning() @property const @trusted nothrow @nogcCheck if the console reader is currently running.const(ConsoleInputEvent)[] pendingEvents() scope @trusted nothrowGet pending events from the internal buffer.Functions 3
bool convertInputRecord(ref const INPUT_RECORD record, ref ConsoleInputEvent event) @trusted nothrow @nogcConvert a Windows INPUT_RECORD to a ConsoleInputEvent.bool isPrintableKey(ushort vk) pure @safe nothrow @nogcCheck if a virtual key code represents a printable character.const(char)[] virtualKeyName(ushort vk) pure @safe nothrow @nogcGet a human-readable name for a virtual key code.