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();

Types 8

enumConsoleEventType : ubyte

Console input event types.

Represents the category of console input event received from Windows.

KEYKeyboard key press or release event.
MOUSEMouse button, movement, or scroll event.
RESIZEConsole window resize event.
FOCUSConsole window focus gain or loss event.
MENUMenu event (typically ignored).
structKeyEvent

Key event data.

Contains information about a keyboard event including the key code, character produced, and modifier key state.

Fields
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).
Methods
bool ctrlPressed() const pure @safe nothrow @nogcCheck if the Ctrl key is pressed.
bool altPressed() const pure @safe nothrow @nogcCheck if the Alt key is pressed.
bool shiftPressed() const pure @safe nothrow @nogcCheck if the Shift key is pressed.

Mouse event data.

Contains information about mouse position, button state, and event type.

Fields
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.
Methods
bool isMove() const pure @safe nothrow @nogcCheck if this is a mouse move event.
bool isDoubleClick() const pure @safe nothrow @nogcCheck if this is a double-click event.
bool isMouseWheel() const pure @safe nothrow @nogcCheck if this is a mouse wheel event.
bool leftButtonDown() const pure @safe nothrow @nogcCheck if the left mouse button is pressed.
bool rightButtonDown() const pure @safe nothrow @nogcCheck if the right mouse button is pressed.

Window resize event.

Contains the new console window dimensions in character cells.

Fields
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.

Fields
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.

Fields
ConsoleEventType typeThe type of this event.
aliasConsoleInputCallback = void delegate( ref ConsoleInput console, scope const(ConsoleInputEvent)[] events ) @safe nothrow

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.
Methods
ConsoleInput create() static @trusted nothrowCreate a detached console input reader.
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.
StartStatus start(ref EventLoop loop) @trusted nothrowStart the console input reader.
void stop() @trusted nothrowStop the console input reader.
void dispose() @trusted nothrowDispose of all resources.
const(ConsoleInputEvent)[] pendingEvents() scope @trusted nothrowGet pending events from the internal buffer.

Functions 3

fnbool convertInputRecord(ref const INPUT_RECORD record, ref ConsoleInputEvent event) @trusted nothrow @nogcConvert a Windows INPUT_RECORD to a ConsoleInputEvent.
fnbool isPrintableKey(ushort vk) pure @safe nothrow @nogcCheck if a virtual key code represents a printable character.
fnconst(char)[] virtualKeyName(ushort vk) pure @safe nothrow @nogcGet a human-readable name for a virtual key code.