Skip to content
ConsoleMonster
Class

ScriptedInput

ConsoleMonster.Input

Namespace
ConsoleMonster.Input
Assembly
ConsoleMonster
Implements
IInputSource IDisposable
Modifiers
sealed

Input from a script, for tests, demos and recordings: Down Down Space "ad.evotec" Enter. key names as accepts them (Ctrl+K, Shift+Tab, F2, ?); Down*3 repeats a key (at most 10000 times); quoted text ("text" or 'text') types each character; paste:"text" pastes; resize:80x24 resizes; wait:250 pauses (milliseconds); the mouse at zero-based cells: click:12,5, rclick:12,5 (right button), dclick:12,5 (double click), move:12,5, wheel:12,5,-3 (three notches down; positive is up) and drag:12,5,30,5 (press, move cell by cell, release). Reading past the end throws InputClosedException, so a test whose script is too short fails instead of hanging.

Inheritance

  • object
  • ScriptedInput

Usage

Explore 1 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

Returned or exposed by 1

Constructors

ScriptedInput 2 overloads
public ScriptedInput(string script) #

Creates a scripted source.

Parameters

script string required
The script.
public ScriptedInput(IEnumerable<InputEvent> events) #

Creates a scripted source from events.

Parameters

events System.Collections.Generic.IEnumerable<ConsoleMonster.Input.InputEvent> required
The events.

Methods

public void Append(string script) #

Appends events to the script.

Parameters

script string required
More script.
public void Dispose() #

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public static IReadOnlyList<InputEvent> ParseEvents(string script) #

Parses a script into events (pauses are dropped).

Parameters

script string required
The script.

Returns

IReadOnlyList<InputEvent> The events.
public InputEvent? Read(TimeSpan timeout, CancellationToken cancellationToken) #

Waits up to timeout for the next event.

Parameters

timeout System.TimeSpan required
The longest wait; TimeSpan.Zero polls.
cancellationToken System.Threading.CancellationToken required
Cancels the wait with OperationCanceledException.

Returns

InputEvent? The event, or null when the timeout passed without input.

Exceptions

public void WaitForOutput(ScreenCapture capture, string text, TimeSpan timeout) #

Queues a bounded wait for visible output before subsequently appended input. Reads return timeouts while waiting so the application can finish asynchronous work and repaint; this wait also applies when ScriptedInput.RealTime is false.

Parameters

capture ConsoleMonster.Interactive.ScreenCapture required
The application's real screen capture.
text string required
The ordinal, case-sensitive text expected in the current frame.
timeout System.TimeSpan required
Maximum time from the first read of this step.

Properties

public string Name { get; } #

A short description for diagnostics, for example windows console (ReadConsoleInputW).

public int Remaining { get; } #

How many events remain.

public bool RealTime { get; set; } #

Whether pauses (wait:) really sleep. Off by default so tests run instantly; demos turn it on.

public Action<TimeSpan>? SkippedWait { get; set; } #

Called for each skipped wait step when ScriptedInput.RealTime is false, before the next input event. A recording host can use ScreenCapture.Hold to retain reading pauses without sleeping.

public bool Paced { get; set; } #

When true, a read that does not wait (zero timeout) returns null, so a reader that drains bursts draws a frame after every scripted event (golden tests of each step).

public bool EndsQuietly { get; set; } #

When true, reading past the end returns null (a timeout) instead of throwing.