-
Notifications
You must be signed in to change notification settings - Fork 6
5. Input and keybinds
one-nora edited this page May 10, 2026
·
2 revisions
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
Serializable wrapper around a bound key, using Unity's engine KeyCode.
Meant for user customization via UI.
KeyBind()
KeyBind(KeyCode KeyCode)-
KeyCodethe bound key
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
}-
IsSet()checks whether the key is notKeyCode.None -
IsPressed(ImGui gui)returnstrueonly on the frame the key is first pressed -
IsDown(ImGui gui)returnstruewhile the key is held
-
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, returnstrueif it has been interacted with in the current frame