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 9
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).private 0x0008 LEFT_CTRL_PRESSEDLeft Ctrl key pressed flag.private 0x0004 RIGHT_CTRL_PRESSEDRight Ctrl key pressed flag.private 0x0002 LEFT_ALT_PRESSEDLeft Alt key pressed flag.private 0x0001 RIGHT_ALT_PRESSEDRight Alt key pressed flag.private 0x0010 SHIFT_PRESSEDShift key pressed flag.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.private 0x0001 MOUSE_MOVEDMouse moved flag.private 0x0002 DOUBLE_CLICKDouble click flag.private 0x0004 MOUSE_WHEELEDMouse wheel vertical scroll flag.private 0x0008 MOUSE_HWHEELEDMouse wheel horizontal scroll flag.private 0x0001 FROM_LEFT_1ST_BUTTON_PRESSEDLeft button pressed flag.private 0x0002 RIGHTMOST_BUTTON_PRESSEDRight button pressed flag.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.
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.
private ConsoleInputState _statevoid 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.HANDLE _consoleHandleDWORD _originalModebool _modeChangedConsoleState _consoleStateEventLoop * _loopToken _wakeupTokenConsoleInputCallback onEventThread _workerHANDLE _stopEventbool _shouldStopMutex _bufferMutexConsoleInputEvent[MAX_EVENTS] _eventBuffersize_t _eventCountthis()Functions 4
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.Variables 3
int _errnoThread-local errno for Windows compatibility.
MAX_EVENTS = 64Maximum number of events buffered per read.
ENABLE_QUICK_EDIT_MODE = 0x0040Quick Edit mode flag (intercepts mouse clicks for text selection). Must be disabled to receive mouse button events.