We use cookies on this site to enhance your user experience

UserInputService

UserInputService

The UserInputService is a service used to detect the type of input available on a user’s device via the use of a LocalScript.

The primary purpose of this service is to allow for games to cooperate with multiple forms of available input - such as gamepads, touch screens, and keyboards. It allows a LocalScript to perform different actions depending on the device, and in turn, helps developers provide the best experience for the end user.

Some usages of this service include detecting user input when they interact with GUIs, tools, and other game instances. In order to detect user input, the service must look for a service event. For example, the service can detect events such as when the user touches the screen of a mobile device using UserInputService/TouchStarted, or connects a Gamepad such as an Xbox controller to their device using UserInputService/GamepadConnected.

Since this service is client-side only, it will only work when used in a LocalScript. It will not work when used within a Script. Client-side only means that users in the game can only detect their own input - and not the input of other users.

Properties

Name Type Description
bool

Indicates whether the user’s device has an accelerometer.

bool

Indicates if the device being used by a user has a gamepad available.

bool

Indicates if the user’s device has a gyroscope.

bool

Becomes true if the device being used by a user has a keyboard available.

bool

Toggles whether or not Roblox’s mobile controls are hidden on mobile devices or not. When set to true the controls are hidden. Defaults to false.

MouseBehavior

Sets how the user’s mouse behaves based on the Enum/MouseBehavior Enum.

float

Scales the delta (change) output of the user’s mouse.

bool

Becomes true if the device being used by a user has a mouse available.

bool

Allows for the mouse icon’s visibility to be toggled on and off.

Vector2

Determines the position of the on-screen keyboard.

Vector2

Determines the size of the on-screen keyboard.

bool

Determines whether an on-screen keyboard is currently visible on the user’s screen.

bool

A UserInputService property that becomes true if the device being used by a user has a touch-screen available.

bool

Indicates whether the user is using a virtual reality headset.

Inherited from Instance

Archivable ClassName DataCost Name Parent RobloxLocked

Functions

Name Type Description
bool

Returns if specified gamepad supports the corresponding keycode button.

Array

Returns a list of Gamepad 's currently connected.

Instance

Returns an InputObject that describes the device’s current acceleration.

Instance

Returns an InputObject that describes the device’s current gravity vector.

Tuple

Returns an InputObject and a CFrame that describes the device’s current rotation vector.

Instance

Returns the currently selected /TextBox, or nil if none is selected.

bool

Returns true if ‘‘gamepadNum’’ is connected to the client.

Array

Returns an array of /InputObject for each input on the gamepad with each input’s last input state.

Array

Returns a table of InputObjects, whose KeyCodes are currently being pressed.

UserInputType

Returns the most recent 'UserInputType` that the client has used.

Array

Returns an array of /InputObjects that corresponds to all the mouse buttons being currently pressed down.

Vector2

Returns the current change in movement of the mouse, but only if the mouse is locked.

Vector2

Returns the current screen location of the mouse.

Array

Returns a list of gamepad 's in a specific order.

Array

Returns the KeyCode that the connected gamepadNum supports.

CFrame

Returns a CFrame describing the position & orientation of a specified virtual reality device.

bool

Returns true if the specified gamepad button is being pressed, for the specified gamepad number.

bool

Indicates whether the user is holding down the specified key.

bool

Returns true if the specified mouse button is currently down.

bool

Returns true if the specified Gamepad is allowed to toggle GUI Navigation & Selection.

void

Recenters the CFrame to the current location of the VR headset being worn by the user.

void

Sets whether or not the specified Gamepad is allowed to move the GUI navigator around.

Inherited from Instance

ClearAllChildren Clone Destroy FindFirstAncestor FindFirstAncestorOfClass FindFirstAncestorWhichIsA FindFirstChild FindFirstChildOfClass FindFirstChildWhichIsA GetChildren GetDebugId GetDescendants GetFullName GetPropertyChangedSignal IsA IsAncestorOf IsDescendantOf WaitForChild

Events

Name Type Description

Fired when a user moves a device that has an accelerometer. Used to track real-world device movement within a Roblox game.

Fired when the force of gravity changes on a device that has an enabled accelerometer - such as an Apple iPad or iPhone or a Google Android phone.

Fired when a user rotates a device that has a gyroscope.

Fires when a gamepad is connected to the client. Passes the ‘‘gamepadNum’’ of the gamepad that was connected.

Fires when a gamepad is disconnected from the client. Passes the gamepadNum of the gamepad that was disconnected .

Fired when a user begins interacting via a Human-Computer Interface device - such as a mouse or gamepad.

Fired when a user changes how they’re interacting via a Human-Computer Interface device.

Fired when a user stops interacting via a Human-Computer Interface device.

Fires whenever there’s a jump request from the client.

Fires when the client’s /UserInputService/UserInputType is changed.

Fired when the client loses focus on a /TextBox.

Fired when the client focuses on a /TextBox.

Fired when a user releases their finger from the screen on a TouchEnabled device - such as the screen of an Apple iPad or iPhone or a Google Android phone.

Fired when a user holds at least one finger for a short amount of time on the same screen position on a TouchEnabled device - such as the screen of an Apple iPad or iPhone or a Google Android phone.

Fired when a user moves their finger on a TouchEnabled device - such as the screen of an Apple iPad or iPhone or a Google Android phone.

Fired when a user drags at least one finger on a TouchEnabled device - such as the screen of an Apple iPad or iPhone or a Google Android phone.

Fired when a user pinches their fingers on a TouchEnabled device - such as the screen of an Apple iPad or iPhone or a Google Android phone.

Fired when a user rotates two fingers on a TouchEnabled device - such as the screen of an Apple iPad or iPhone or a Google Android phone.

Fired when a user places their finger on a TouchEnabled device - such as the screen of an Apple iPad or iPhone or a Google Android phone.

Fired when a user swipes their fingers on a TouchEnabled device - such as the screen of an Apple iPad or iPhone or a Google Android phone.

Fired when a user taps their finger on a TouchEnabled device - such as the screen of an Apple iPad or iPhone or a Google Android phone.

Fired when a user taps the game world on a TouchEnabled device - such as an Apple iPad or iPhone or a Google Android phone.

Fires locally when the /CFrame of a specified Virtual Reality (VR) device changes - allowing the user to see what body part moved and how it moved.

Fires when the Roblox client loses focus.

Fires when the Roblox client gains focus.

Inherited from Instance

AncestryChanged Changed ChildAdded ChildRemoved DescendantAdded DescendantRemoving