Skip to content

Text Input

ODD Games edited this page Oct 14, 2026 · 4 revisions

Text Input

using static ODDGames.BugpunchSdk.ActionExecutor;

Enter text into input fields and simulate keyboard input.

TextInput

Replace the text of an input field:

// Using the adjacent label (recommended for forms)
await TextInput(Adjacent("Username:"), "testuser");
await TextInput(Adjacent("Password:"), "secret123");

// Using the element name
await TextInput(Name("SearchField"), "search query");

// Press Enter afterwards (submits the field)
await TextInput(Adjacent("Message:"), "Hello world", pressEnter: true);

How It Works

  1. Finds a TMP_InputField or legacy InputField on the matched element, its children or its parents
  2. Clicks the field to focus it
  3. Sets the field's text (existing text is replaced) and moves the caret to the end
  4. Optionally presses Enter

TMP_InputField reads keystrokes through IMGUI rather than the Input System, so the text is assigned directly instead of being typed character by character. onValueChanged still fires; per-keystroke validation does not run.

Parameters

Parameter Type Default Description
search Search required How to find the input field
input string required Text to enter
seconds float 10 Seconds to wait for the field
pressEnter bool false Press Enter after setting the text

Type

Type is the lower-level variant: it targets the matched element itself (the component must be on that GameObject), and can append instead of replacing:

// Replace (default)
await Type(Name("UsernameInput"), "player1");

// Append to what's already there
await Type(Name("ChatInput"), " and more", clearFirst: false);

// Submit
await Type(Name("SearchInput"), "search term", pressEnter: true);

Signature: Type(Search search, string text, bool clearFirst = true, bool pressEnter = false, float searchTime = -1f, int index = 0).

Finding Input Fields

By Adjacent Label

Best for form fields with labels:

await TextInput(Adjacent("Email:"), "user@example.com");
await TextInput(Adjacent("Phone*"), "555-1234");

By Name

When the input field has a unique name:

await TextInput(Name("UsernameInput"), "player1");
await TextInput(Name("ChatInput"), "Hello!");

By Type

Find the first available input:

await TextInput(Type<TMP_InputField>(), "test");

Keyboard Input

Keyboard actions inject real key events on a virtual Input System keyboard. They need using UnityEngine.InputSystem; when you use the Key enum.

PressKey

Press and release a single key:

using UnityEngine.InputSystem;

// By Input System Key
await PressKey(Key.Escape);

// By KeyCode
await PressKey(KeyCode.Space);
await PressKey(KeyCode.Return);

// By character
await PressKey('a');

// By name: any KeyCode name, or enter / esc / up / down / left / right / backspace / del
await PressKey("enter");
await PressKey("Tab");

PressKeys

Press one key per character of a string:

await PressKeys("hello world");

This doesn't focus anything first and doesn't add Shift for capitals or symbols — it's for driving key bindings, not filling text fields. Use TextInput / Type for fields.

TypeText

Queue Input System text events (one character per frame) to whatever currently has keyboard focus:

await TypeText("typed via text events");

Useful for UI that listens to Keyboard.onTextInput. TMP_InputField ignores these events, so use TextInput for it.

HoldKey / HoldKeys

Hold one or more keys down together for a duration:

using UnityEngine.InputSystem;

// Move forward for 2 seconds
await HoldKey(Key.W, 2f);

// Sprint: hold W and Shift together
await HoldKeys(1.5f, Key.W, Key.LeftShift);

// KeyCode overloads too
await HoldKey(KeyCode.Space, 0.5f);

Form Examples

Login Form

await TextInput(Adjacent("Username:"), "testuser");
await TextInput(Adjacent("Password:"), "password123");
await Click(Text("Login"));

Registration Form

await TextInput(Adjacent("First Name:"), "John");
await TextInput(Adjacent("Last Name:"), "Doe");
await TextInput(Adjacent("Email:"), "john.doe@example.com");
await TextInput(Adjacent("Password:"), "SecurePass123!");
await TextInput(Adjacent("Confirm Password:"), "SecurePass123!");
await Click(Text("Register"));

Search with Submit

await TextInput(Name("SearchInput"), "search term", pressEnter: true);

Keyboard Shortcuts

Hold the modifier and the key together:

using UnityEngine.InputSystem;

// Ctrl+S
await HoldKeys(0.1f, Key.LeftCtrl, Key.S);

Game Controls

await PressKey(KeyCode.W);       // Step forward
await PressKey(KeyCode.Space);   // Jump
await PressKey(KeyCode.Escape);  // Pause menu

Supported Components

  • UnityEngine.UI.InputField (Legacy)
  • TMPro.TMP_InputField (TextMeshPro)

Related Pages

Clone this wiki locally