Skip to content

5. Input and keybinds

one-nora edited this page May 10, 2026 · 2 revisions

Input Utility

Tracks keyboard state from Imui input events. It only has 1 method

  • InputUtility.GetKeyDown(KeyCode key) returns whether a key is currently down

Recommended for special keys such as KeyCode.LeftControl, KeyCode.RightControl, KeyCode.LeftShift, KeyCode.RightShift, KeyCode.LeftAlt and KeyCode.RightAlt

If you need a key that can change as the user wants, use KeyBind

Key binds

Serializable wrapper around a bound key, using Unity's engine KeyCode. Meant for user customization via UI.

Constructors

KeyBind()
KeyBind(KeyCode KeyCode)

Members

  • KeyCode the bound key

Examples

KeyBind myBind = new KeyBind(KeyCode.P);

//...

if (!myBind.IsSet())
{
	// do something if not bound
}

// Handling
if (myBind.IsPressed(gui))
{
    // do action once
}

if (myBind.IsDown(gui))
{
	// do action as long as its pressed
}

// Draw keybind

if (gui.SimpleKeybind("My keybind", ref myBind))
{
	// do action if keybind was interacted with
}

Input helpers

  • IsSet() checks whether the key is not KeyCode.None
  • IsPressed(ImGui gui) returns true only on the frame the key is first pressed
  • IsDown(ImGui gui) returns true while the key is held

Draw UI

  • gui.SimpleKeybind(string keyName, ref KeyBind keyBind) draws a button that shows the current bound key, on click allows the user to change the bound key, returns true if it has been interacted with in the current frame

Clone this wiki locally