KROYSDOCS
HomeWhat's newv0.1.0

Input

Input actions, contexts, rebinding, gamepads and raw keyboard/mouse state.

Kindclass
NamespaceKroys.EngineScripting
Members37
SourceInput.cs
EXAMPLE

In a script

Action, key and mouse-button queries made in FixedUpdate read the fixed step: each press and release is reported on exactly one step, whatever the frame rate. Queries made in Update and LateUpdate read the rendered frame. Player 0 owns the keyboard and mouse; gamepads are assigned to the lowest player without one as they connect.

Gameplay.cs
public sealed class InteractPrompt : EntityScript
{
    protected override void OnFixedUpdate(float fixedDeltaTime)
    {
        // Actions come from the project's input map (Content/Settings/Input.kinput):
        // "Move" is WASD, the arrow keys and the left stick; "Interact" is E or the west button.
        Vector2 move = Input.GetAxis2D("Move");
        if (move.LengthSquared() > 0.01f)
            Debug.Log($"moving {move.X:0.00}, {move.Y:0.00}");

        // In OnFixedUpdate every press is reported on exactly one fixed step.
        if (Input.IsActionPressed("Interact"))
            Debug.Log("interact");
    }

    protected override void OnUpdate(float deltaTime)
    {
        // Raw keys and the mouse are there too, for debug keys and tools.
        if (Input.IsKeyPressed(KeyCode.F3))
            Debug.Log($"mouse at {Input.MousePosition}, moved {Input.MouseDelta}");
        if (Input.IsGamepadConnected(0) && Input.IsGamepadButtonDown(GamepadButton.Start))
            Debug.Log("pause");
    }
}
REFERENCE

Members

Properties
#public static int GamepadCount { get; }
Number of connected gamepads.
propertystatic
#public static Vector2 MousePosition { get; }
Mouse cursor position in window coordinates.
propertystatic
#public static Vector2 MouseDelta { get; }
Mouse cursor movement since the last frame.
propertystatic
#public static Vector2 ScrollDelta { get; }
Mouse wheel/trackpad scroll movement since the last frame.
propertystatic
Methods
#public static bool IsActionPressed(string action)
Returns true only on the frame (or fixed step) a named input action changes from up to down.
methodstatic
#public static bool IsActionPressed(string action, int player)
Returns true only on the frame (or fixed step) an input action of a player changes from up to down.
methodstatic
#public static bool IsActionHeld(string action)
Returns whether a named input action is currently held.
methodstatic
#public static bool IsActionHeld(string action, int player)
Returns whether an input action of a player is currently held.
methodstatic
#public static bool IsActionReleased(string action)
Returns true only on the frame (or fixed step) a named input action changes from down to up.
methodstatic
#public static bool IsActionReleased(string action, int player)
Returns true only on the frame (or fixed step) an input action of a player changes from down to up.
methodstatic
#public static float GetAxis(string action)
Returns a one-dimensional named input axis.
methodstatic
#public static Vector2 GetAxis2D(string action)
Returns a two-dimensional named input axis.
methodstatic
#public static float GetAxis(string action, int player)
Returns a one-dimensional input axis of a player.
methodstatic
#public static Vector2 GetAxis2D(string action, int player)
Returns a two-dimensional input axis of a player.
methodstatic
#public static void SetContextEnabled(string context, bool enabled)
Enables or disables an input context.
methodstatic
#public static bool IsContextEnabled(string context)
Returns whether an input context is enabled.
methodstatic
#public static void PushContext(string context)
Enables a context and puts it above the other contexts of the same priority (for example a vehicle map over the gameplay map). A context that consumes input hides the controls it uses from lower contexts.
methodstatic
#public static void PopContext(string context)
Disables a context pushed with PushContext.
methodstatic
#public static bool IsGamepadConnected(int player = 0)
Returns whether a gamepad is assigned to the player.
methodstatic
#public static bool IsGamepadButtonDown(GamepadButton button, int player = 0)
Returns whether a button of the gamepad of a player is held.
methodstatic
#public static float GetGamepadAxis(GamepadAxis axis, int player = 0)
Raw axis of the gamepad of a player (sticks -1..1, triggers 0..1), without dead zone.
methodstatic
#public static bool TryGetPressedControl(out InputControl control, int player = 0)
The first control the player pressed this frame, for rebinding screens that wait for a key.
methodstatic
#public static int GetBindingCount(string action)
Number of bindings of an action across its contexts; the indices for GetBinding and Rebind.
methodstatic
#public static InputControl? GetBinding(string action, int index, int player = 0)
The control a binding of an action currently reads for the player (after rebinding), or null.
methodstatic
#public static RebindResult Rebind(string action, int index, InputControl control, int player = 0, bool allowConflicts = false)
Points one binding of an action at another control for the player. A control another action uses in the same context is rejected with RebindResult.Conflict unless allowConflicts is set. Call SaveBindings to keep it.
methodstatic
#public static void ResetBindings(int player = 0)
Restores the authored bindings of a player.
methodstatic
#public static bool SaveBindings()
Saves the rebinding of every player to the user settings. Returns false when the host has no settings location (the editor) or the file cannot be written.
methodstatic
#public static bool IsKeyDown(KeyCode keyCode)
Returns whether a key is currently held down.
methodstatic
#public static bool IsKeyPressed(KeyCode keyCode)
Returns true only on the frame a key changes from up to down.
methodstatic
#public static bool GetKeyDown(KeyCode keyCode)
Alias for IsKeyPressed, matching common game-engine naming.
methodstatic
#public static bool IsKeyReleased(KeyCode keyCode)
Returns true only on the frame a key changes from down to up.
methodstatic
#public static bool GetKeyUp(KeyCode keyCode)
Alias for IsKeyReleased, matching common game-engine naming.
methodstatic
#public static bool IsMouseButtonDown(MouseButton button)
Returns whether a mouse button is currently held down.
methodstatic
#public static bool IsMouseButtonPressed(MouseButton button)
Returns true only on the frame a mouse button changes from up to down.
methodstatic
#public static bool GetMouseButtonDown(MouseButton button)
Alias for IsMouseButtonPressed.
methodstatic
#public static bool IsMouseButtonReleased(MouseButton button)
Returns true only on the frame a mouse button changes from down to up.
methodstatic
#public static bool GetMouseButtonUp(MouseButton button)
Alias for IsMouseButtonReleased.
methodstatic
Signatures
public static bool IsActionPressed(string action)
public static bool IsActionPressed(string action, int player)
public static bool IsActionHeld(string action)
public static bool IsActionHeld(string action, int player)
public static bool IsActionReleased(string action)
public static bool IsActionReleased(string action, int player)
public static float GetAxis(string action)
public static Vector2 GetAxis2D(string action)
public static float GetAxis(string action, int player)
public static Vector2 GetAxis2D(string action, int player)
public static void SetContextEnabled(string context, bool enabled)
public static bool IsContextEnabled(string context)
public static void PushContext(string context)
public static void PopContext(string context)
public static int GamepadCount { get; }
public static bool IsGamepadConnected(int player = 0)
public static bool IsGamepadButtonDown(GamepadButton button, int player = 0)
public static float GetGamepadAxis(GamepadAxis axis, int player = 0)
public static bool TryGetPressedControl(out InputControl control, int player = 0)
public static int GetBindingCount(string action)
public static InputControl? GetBinding(string action, int index, int player = 0)
public static RebindResult Rebind(string action, int index, InputControl control, int player = 0, bool allowConflicts = false)
public static void ResetBindings(int player = 0)
public static bool SaveBindings()
public static bool IsKeyDown(KeyCode keyCode)
public static bool IsKeyPressed(KeyCode keyCode)
public static bool GetKeyDown(KeyCode keyCode)
public static bool IsKeyReleased(KeyCode keyCode)
public static bool GetKeyUp(KeyCode keyCode)
public static bool IsMouseButtonDown(MouseButton button)
public static bool IsMouseButtonPressed(MouseButton button)
public static bool GetMouseButtonDown(MouseButton button)
public static bool IsMouseButtonReleased(MouseButton button)
public static bool GetMouseButtonUp(MouseButton button)
public static Vector2 MousePosition { get; }
public static Vector2 MouseDelta { get; }
public static Vector2 ScrollDelta { get; }

KroysEngine 0.1.0 documentation, built from the engine repository by Tools/BuildDocsSite.py.