A Singleton that deals with inputs.
    public static class Input

A Singleton that deals with inputs. This includes key presses, mouse buttons and movement, joypads, and input actions. Actions and their events can be set in the Project Settings / Input Map tab. Or be set with InputMap.

Inheritance Chain

Static Methods

    public static void ActionPress(string action)

This will simulate pressing the specified action.

    public static void ActionRelease(string action)

If the specified action is already pressed, this will release it.

    public static void AddJoyMapping(string mapping, bool updateExisting = false)

Add a new mapping entry (in SDL2 format) to the mapping database. Optionally update already connected devices.

    public static Vector3 GetAccelerometer()

If the device has an accelerometer, this will return the acceleration. Otherwise, it returns an empty Vector3.

    public static Array GetConnectedJoypads()

Returns an Array containing the device IDs of all currently connected joypads.

    public static Vector3 GetGravity()

If the device has an accelerometer, this will return the gravity. Otherwise, it returns an empty Vector3.

    public static Vector3 GetGyroscope()

If the device has a gyroscope, this will return the rate of rotation in rad/s around a device’s x, y, and z axis. Otherwise, it returns an empty Vector3.

    public static float GetJoyAxis(int device, int axis)

Returns the current value of the joypad axis at given index (see JOY_* constants in [@GlobalScope])

    public static int GetJoyAxisIndexFromString(string axis)

    public static string GetJoyAxisString(int axisIndex)

    public static int GetJoyButtonIndexFromString(string button)

    public static string GetJoyButtonString(int buttonIndex)

    public static string GetJoyGuid(int device)

Returns a SDL2 compatible device guid on platforms that use gamepad remapping. Returns “Default Gamepad” otherwise.

    public static string GetJoyName(int device)

Returns the name of the joypad at the specified device index

    public static float GetJoyVibrationDuration(int device)

Returns the duration of the current vibration effect in seconds.

    public static Vector2 GetJoyVibrationStrength(int device)

Returns the strength of the joypad vibration: x is the strength of the weak motor, and y is the strength of the strong motor.

    public static Vector2 GetLastMouseSpeed()

Returns the mouse speed for the last time the cursor was moved, and this until the next frame where the mouse moves. This means that even if the mouse is not moving, this function will still return the value of the last motion.

    public static Vector3 GetMagnetometer()

If the device has a magnetometer, this will return the magnetic field strength in micro-Tesla for all axes.

    public static int GetMouseButtonMask()

Returns mouse buttons as a bitmask. If multiple mouse buttons are pressed at the same time the bits are added together.

    public static MouseMode GetMouseMode()

Return the mouse mode. See the constants for more information.

    public static bool IsActionJustPressed(string action)

Returns true when the user starts pressing the action event, meaning it’s true only on the frame that the user pressed down the button.

This is useful for code that needs to run only once when an action is pressed, instead of every frame while it’s pressed.

    public static bool IsActionJustReleased(string action)

Returns true when the user stops pressing the action event, meaning it’s true only on the frame that the user released the button.

    public static bool IsActionPressed(string action)

Returns true if you are pressing the action event.

    public static bool IsJoyButtonPressed(int device, int button)

Returns true if you are pressing the joypad button. (see JOY_* constants in [@GlobalScope])

    public static bool IsJoyKnown(int device)

Returns true if the system knows the specified device. This means that it sets all button and axis indices exactly as defined in the JOY_* constants (see [@GlobalScope]). Unknown joypads are not expected to match these constants, but you can still retrieve events from them.

    public static bool IsKeyPressed(int scancode)

Returns true if you are pressing the key. You can pass KEY_*, which are pre-defined constants listed in [@GlobalScope].

    public static bool IsMouseButtonPressed(int button)

Returns true if you are pressing the mouse button. You can pass button, which are pre-defined constants listed in [@GlobalScope].

    public static void JoyConnectionChanged(int device, bool connected, string name, string guid)

    public static void ParseInputEvent(InputEvent @event)

Feeds an InputEvent to the game. Can be used to artificially trigger input events from code.

    public static void RemoveJoyMapping(string guid)

Removes all mappings from the internal db that match the given uid.

    public static void SetCustomMouseCursor(Resource image, CursorShape shape = CursorShape.Arrow, Vector2? hotspot = default(Vector2?))

Set a custom mouse cursor image, which is only visible inside the game window. The hotspot can also be specified. See enum CURSOR_* for the list of shapes.

    public static void SetMouseMode(MouseMode mode)

Set the mouse mode. See the constants for more information.

    public static void StartJoyVibration(int device, float weakMagnitude, float strongMagnitude, float duration = 0f)

Starts to vibrate the joypad. Joypads usually come with two rumble motors, a strong and a weak one. weak_magnitude is the strength of the weak motor (between 0 and 1) and strong_magnitude is the strength of the strong motor (between 0 and 1). duration is the duration of the effect in seconds (a duration of 0 will try to play the vibration indefinitely).

Note that not every hardware is compatible with long effect durations, it is recommended to restart an effect if in need to play it for more than a few seconds.

    public static void StopJoyVibration(int device)

Stops the vibration of the joypad.

    public static void WarpMousePosition(Vector2 to)

Sets the mouse position to the specified vector.

Signals

    "joy_connection_changed" (int index, bool connected)

Emitted when a joypad device has been connected or disconnected.

Inner Types

CursorShape

Name Value Description
Arrow 0 Arrow cursor. Standard, default pointing cursor.
Ibeam 1 I-beam cursor. Usually used to show where the text cursor will appear when the mouse is clicked.
PointingHand 2 Pointing hand cursor. Usually used to indicate the pointer is over a link or other interactable item.
Cross 3 Cross cursor. Typically appears over regions in which a drawing operation can be performance or for selections.
Wait 4 Wait cursor. Indicates that the application is busy performing an operation.
Busy 5 Busy cursor. See [code]CURSOR_WAIT[/code].
Drag 6 Drag cursor. Usually displayed when dragging something.
CanDrop 7 Can drop cursor. Usually displayed when dragging something to indicate that it can be dropped at the current position.
Forbidden 8 Forbidden cursor. Indicates that the current action is forbidden (for example, when dragging something) or that the control at a position is disabled.
Vsize 9 Vertical resize mouse cursor. A double headed vertical arrow. It tells the user they can resize the window or the panel vertically.
Hsize 10 Horizontal resize mouse cursor. A double headed horizontal arrow. It tells the user they can resize the window or the panel horizontally.
Bdiagsize 11 Window resize mouse cursor. The cursor is a double headed arrow that goes from the bottom left to the top right. It tells the user they can resize the window or the panel both horizontally and vertically.
Fdiagsize 12 Window resize mouse cursor. The cursor is a double headed arrow that goes from the top left to the bottom right, the opposite of [code]CURSOR_BDIAGSIZE[/code]. It tells the user they can resize the window or the panel both horizontally and vertically.
Move 13 Move cursor. Indicates that something can be moved.
Vsplit 14 Vertical split mouse cursor. On Windows, it’s the same as [code]CURSOR_VSIZE[/code].
Hsplit 15 Horizontal split mouse cursor. On Windows, it’s the same as [code]CURSOR_HSIZE[/code].
Help 16 Help cursor. Usually a question mark.

MouseMode

Name Value Description
Visible 0 Makes the mouse cursor visible if it is hidden.
Hidden 1 Makes the mouse cursor hidden if it is visible.
Captured 2 Captures the mouse. The mouse will be hidden and unable to leave the game window. But it will still register movement and mouse button presses.
Confined 3 Makes the mouse cursor visible but confines it to the game window.
Tags: