Skip to content

InputAPI reference

Class ActionPrompts

Namespace: MicroEngine.Input
Assembly: MicroEngine.dll
Guide: Input

Tells the player which control presses an action on the device they are using, so dialogues, tutorials, help screens and hints never name a key the player does not have. The text follows the active device (the one that last pressed an action, touch while the on-screen controls are shown), the action’s current bindings (remapping included) and the touch layout, and changes as soon as the player switches device: read it every frame, or when Version changes. Games get one in Prompts.

C#
public sealed class ActionPrompts

Inheritance

object ← ActionPrompts

Examples

C#
font.Draw(r, Prompts.Format("Press {attack} to swing the sword"), position, color);
// Keyboard: "Press Z to swing...", Xbox pad: "Press A...", PlayStation: "Press ×...", phone: "Press A..." (the touch button's label)

Constructors

ActionPrompts(InputMap, VirtualControls?)

Prompts for the actions of input and the controls of touch (optional).

C#
public ActionPrompts(InputMap input, VirtualControls? touch = null)

Parameters

input InputMap

touch VirtualControls?

Properties

Device

The device prompts are shown for: Override, else the device that last pressed an action; before any press (or after scripted input), touch when the on-screen controls are shown or the screen is touch-first, otherwise the keyboard.

C#
public InputDevice Device { get; }

Property Value

InputDevice

KeyLabels

The labels of the player’s keyboard layout (the platform’s IKeyLabels, set by the engine), so a key is named as printed on the player’s keyboard: the key in A’s place is “Q” on AZERTY. Null, or a key the layout does not label, uses KeyName.

C#
public IKeyLabels? KeyLabels { get; set; }

Property Value

IKeyLabels?

Override

Forces prompts for one device (a “show keyboard controls” option, tests); null follows the player.

C#
public InputDevice? Override { get; set; }

Property Value

InputDevice?

PadStyle

The gamepad family button names follow: PadStyleOverride, else the connected pad’s.

C#
public GamepadStyle PadStyle { get; }

Property Value

GamepadStyle

PadStyleOverride

Forces button names of one gamepad family; null follows the connected pad.

C#
public GamepadStyle? PadStyleOverride { get; set; }

Property Value

GamepadStyle?

Version

Changes whenever the text of prompts may have changed (another device, another pad family), so a game that lays text out once (wrapping, measuring) knows when to do it again.

C#
public int Version { get; }

Property Value

int

Methods

All(string, InputDevice?)

Every control that presses action on the device, in binding order (an empty list when none does).

C#
public IReadOnlyList<ActionPrompt> All(string action, InputDevice? device = null)

Parameters

action string

device InputDevice?

Returns

IReadOnlyList<ActionPrompt>

ButtonName(PadButton, GamepadStyle)

The name printed on a gamepad button of style. PadButton names positions as on an Xbox pad; PlayStation pads show shapes there (×, ○, □, △, all in the built-in font), Nintendo pads swap A/B and X/Y.

C#
public static string ButtonName(PadButton button, GamepadStyle style = GamepadStyle.Xbox)

Parameters

button PadButton

style GamepadStyle

Returns

string

Directions(string?, string?, string?, string?, InputDevice?, string?)

How to show a group of directions together (“move”): on a keyboard the first key of each (“←→↑↓”, “WASD”), on a gamepad “D-pad” or “Stick”, on a touch screen the name of the d-pad or joystick that presses them all.

C#
public string Directions(string? left = null, string? right = null, string? up = null, string? down = null, InputDevice? device = null, string? separator = null)

Parameters

left string?

right string?

up string?

down string?

device InputDevice?

separator string?

Returns

string

Remarks

Keys are listed up, left, down, right, so a WASD set reads “WASD”. With separator set, a keyboard shows every key set the directions share (“↑←↓→ / WASD”), for a help screen.

Format(string, Func<ActionPrompt, string>?)

Replaces each {action} in template with that action’s prompt ({{ and }} are literal braces); {move} stands for Directions. Names that are neither bound, pressed by a touch control nor labelled are left as written. decorate may wrap each prompt (“[Z]”).

C#
public string Format(string template, Func<ActionPrompt, string>? decorate = null)

Parameters

template string

decorate Func<ActionPrompt, string>?

Returns

string

Get(string, InputDevice?)

How to show action on device (default: Device): the first binding the device has.

C#
public ActionPrompt Get(string action, InputDevice? device = null)

Parameters

action string

device InputDevice?

Returns

ActionPrompt

KeyName(Key)

The name a key has on a US keyboard: “Z”, “Space”, “Esc”, “←” (prompts prefer the layout’s label, KeyText).

C#
public static string KeyName(Key key)

Parameters

key Key

Returns

string

KeyText(Key)

What a key cap shows on the player’s keyboard: the layout’s label (KeyLabels), else KeyName.

C#
public string KeyText(Key key)

Parameters

key Key

Returns

string

Knows(string)

Whether name is something a template may name.

C#
public bool Knows(string name)

Parameters

name string

Returns

bool

SetLabel(string, InputDevice?, string?)

Replaces the prompt of action with text on device, or on every device when it is null (“tap”, “the left side”). Null text removes the label.

C#
public void SetLabel(string action, InputDevice? device, string? text)

Parameters

action string

device InputDevice?

text string?

Split(string)

The pieces of a template: literal text, and actions with their prompts, for drawing prompts as glyphs between runs of text (see MicroEngine.UI.PromptText).

C#
public IReadOnlyList<(string Text, ActionPrompt? Prompt)> Split(string template)

Parameters

template string

Returns

IReadOnlyList<(string Text, ActionPrompt? Prompt)>

StyleFromName(string?)

The gamepad family a pad’s name suggests (browsers and raylib report names, not types).

C#
public static GamepadStyle StyleFromName(string? name)

Parameters

name string?

Returns

GamepadStyle

Text(string, InputDevice?)

The first control’s text, as Get.

C#
public string Text(string action, InputDevice? device = null)

Parameters

action string

device InputDevice?

Returns

string

TextAll(string, string, InputDevice?)

Every control’s text joined with separator: “Z / Space / Enter” for a help screen.

C#
public string TextAll(string action, string separator = " / ", InputDevice? device = null)

Parameters

action string

separator string

device InputDevice?

Returns

string