API:Class/UserInputService

Client only:This service is client-side only! You should use a LocalScript instead of a Script when using it.
Filtered-inheritance mode: While this class technically inherits all Instance class members, some (if not all) have been hidden because they serve no purpose for this object.
Service: This class is a service. It is a top-level singleton which can be obtained with the GetService method.
Uncreatable: This object cannot be created with Instance.new.

UserInputService.pngUserInputService : Object Icon.pngInstance

The UserInputService is a service which is used to detect the type of input available on a user's device via the use of a LocalScript. It allows LocalScripts to perform different actions depending on the device used to provide the best experience for the end user. The purpose of this service is primarily to allow for games to cooperate with multiple forms of available input.

Properties

PropertiesmemberhiddenProperties [toggle]

boolAccelerometerEnabled [readonly]

Returns true if the local device has an accelerometer, otherwise returns false.

|RMD member="API:Class/UserInputService/AccelerometerEnabled"|Returns true if the local device has an accelerometer, otherwise returns false.|/RMD|
boolGamepadEnabled [readonly]

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

|RMD member="API:Class/UserInputService/GamepadEnabled"|Becomes true if the device being used by a user has a gamepad available.|/RMD|
boolGyroscopeEnabled [readonly]

Returns true if the local device has a gyroscope, otherwise returns false.

|RMD member="API:Class/UserInputService/GyroscopeEnabled"|Returns true if the local device has a gyroscope, otherwise returns false.|/RMD|
boolKeyboardEnabled [readonly]

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

|RMD member="API:Class/UserInputService/KeyboardEnabled"|Becomes true if the device being used by a user has a keyboard available.|/RMD|
boolModalEnabled

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.

|RMD member="API:Class/UserInputService/ModalEnabled"|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.|/RMD|
MouseBehaviorMouseBehavior

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

|RMD member="API:Class/UserInputService/MouseBehavior"|Sets how the user's mouse behaves based on the MouseBehavior Enum.|/RMD|
floatMouseDeltaSensitivity

Scales the Delta output of the user's mouse.

|RMD member="API:Class/UserInputService/MouseDeltaSensitivity"|Scales the Delta output of the user's mouse.|/RMD|
boolMouseEnabled [readonly]

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

|RMD member="API:Class/UserInputService/MouseEnabled"|Becomes true if the device being used by a user has a mouse available.|/RMD|
boolMouseIconEnabled

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

|RMD member="API:Class/UserInputService/MouseIconEnabled"|Allows for the mouse icon's visibility to be toggled on and off.|/RMD|
Vector2OnScreenKeyboardPosition [readonly]

The position of the on-screen keyboard, if visible.

|RMD member="API:Class/UserInputService/OnScreenKeyboardPosition"|The position of the on-screen keyboard, if visible.|/RMD|
Vector2OnScreenKeyboardSize [readonly]

The size of the on-screen keyboard, if visible.

|RMD member="API:Class/UserInputService/OnScreenKeyboardSize"|The size of the on-screen keyboard, if visible.|/RMD|
boolOnScreenKeyboardVisible [readonly]

If true, an on-screen keyboard is currently visible.

|RMD member="API:Class/UserInputService/OnScreenKeyboardVisible"|If true, an on-screen keyboard is currently visible.|/RMD|
boolTouchEnabled [readonly]

Becomes true if the device being used by a user has a touch-screen available.

|RMD member="API:Class/UserInputService/TouchEnabled"|Becomes true if the device being used by a user has a touch-screen available.|/RMD|
boolVREnabled [readonly]

Becomes true if the user is using a virtual reality headset.

|RMD member="API:Class/UserInputService/VREnabled"|Becomes true if the user is using a virtual reality headset.|/RMD|
CFrameUserHeadCFrame [deprecated] [readonly]

Deprecated. Do not use.

|RMD member="API:Class/UserInputService/UserHeadCFrame"|Deprecated. Do not use.|/RMD|
Returns true if the local device has an accelerometer, otherwise returns false.
GamepadEnabled [readonly]
Becomes true if the device being used by a user has a gamepad available.
GyroscopeEnabled [readonly]
Returns true if the local device has a gyroscope, otherwise returns false.
KeyboardEnabled [readonly]
Becomes true if the device being used by a user has a keyboard available.
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.
Sets how the user's mouse behaves based on the MouseBehavior Enum.
Scales the Delta output of the user's mouse.
MouseEnabled [readonly]
Becomes true if the device being used by a user has a mouse available.
Allows for the mouse icon's visibility to be toggled on and off.
The position of the on-screen keyboard, if visible.
The size of the on-screen keyboard, if visible.
If true, an on-screen keyboard is currently visible.
TouchEnabled [readonly]
Becomes true if the device being used by a user has a touch-screen available.
VREnabled [readonly]
Becomes true if the user is using a virtual reality headset.
UserHeadCFrame [deprecated] [readonly]
Deprecated. Do not use.

Functions

Functions [toggle]

boolGamepadSupports ( UserInputType gamepadNum, KeyCode gamepadKeyCode )

Returns if specified gamepad supports the corresponding keycode button.

|RMD member="API:Class/UserInputService/GamepadSupports"|Returns if specified gamepad supports the corresponding keycode button.|/RMD|
array<UserInputType>GetConnectedGamepads ( )

Returns a list of Gamepad UserInputTypes currently connected. If no gamepads are connected, this list will be empty.

|RMD member="API:Class/UserInputService/GetConnectedGamepads"|Returns a list of Gamepad UserInputTypes currently connected. If no gamepads are connected, this list will be empty.|/RMD|
InputObjectGetDeviceAcceleration ( )

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

|RMD member="API:Class/UserInputService/GetDeviceAcceleration"|Returns an InputObject that describes the device's current acceleration.|/RMD|
InputObjectGetDeviceGravity ( )

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

|RMD member="API:Class/UserInputService/GetDeviceGravity"|Returns an InputObject that describes the device's current gravity vector.|/RMD|
InputObject, CFrameGetDeviceRotation ( )

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

|RMD member="API:Class/UserInputService/GetDeviceRotation"|Returns an InputObject and a CFrame that describes the device's current rotation vector.|/RMD|
Ref<TextBox>GetFocusedTextBox ( )

Returns the currently selected textbox, or nil if none is selected.

|RMD member="API:Class/UserInputService/GetFocusedTextBox"|Returns the currently selected textbox, or nil if none is selected.|/RMD|
boolGetGamepadConnected ( UserInputType gamepadNum )

Returns true if gamepadNum is connected to the client.

|RMD member="API:Class/UserInputService/GetGamepadConnected"|Returns true if gamepadNum is connected to the client.|/RMD|
array<InputObject>GetGamepadState ( UserInputType gamepadNum )

Returns an array of InputObjects for each input on the gamepad with each input's last input state.

|RMD member="API:Class/UserInputService/GetGamepadState"| Returns an array of InputObjects for each input on the gamepad with each input's last input state.|/RMD|
array<InputObject>GetKeysPressed ( )

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

|RMD member="API:Class/UserInputService/GetKeysPressed"| Returns a table of InputObjects, whose KeyCodes are currently being pressed.|/RMD|
UserInputTypeGetLastInputType ( )

Returns the most recent UserInputType that the client has used.

|RMD member="API:Class/UserInputService/GetLastInputType"|Returns the most recent UserInputType that the client has used.|/RMD|
array<InputObject>GetMouseButtonsPressed ( )

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

|RMD member="API:Class/UserInputService/GetMouseButtonsPressed"|Returns an array of InputObjects that corresponds to all the mouse buttons being currently pressed down.|/RMD|
Vector2GetMouseDelta ( )

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

|RMD member="API:Class/UserInputService/GetMouseDelta"|Returns the current change in movement of the mouse, but only if the mouse is locked.|/RMD|
Vector2GetMouseLocation ( )

Returns the current screen location of the mouse.

|RMD member="API:Class/UserInputService/GetMouseLocation"|Returns the current screen location of the mouse.|/RMD|
array<UserInputType>GetNavigationGamepads ( )

Returns a list of gamepad UserInputTypes in a specific order. It is meant to be iterated over to determine which Gamepad should have navigation control.

|RMD member="API:Class/UserInputService/GetNavigationGamepads"|Returns a list of gamepad UserInputTypes in a specific order. It is meant to be iterated over to determine which Gamepad should have navigation control.|/RMD|
array<KeyCode>GetSupportedGamepadKeyCodes ( UserInputType gamepadNum )

Returns the KeyCodes that the connected gamepadNum supports.

|RMD member="API:Class/UserInputService/GetSupportedGamepadKeyCodes"|Returns the KeyCodes that the connected gamepadNum supports.|/RMD|
CFrameGetUserCFrame ( UserCFrame type )

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

|RMD member="API:Class/UserInputService/GetUserCFrame"|Returns a CFrame describing the position & orientation of a specified virtual reality device.|/RMD|
boolIsKeyDown ( KeyCode keyCode )

Returns true if the user is holding down the specified key.

|RMD member="API:Class/UserInputService/IsKeyDown"| Returns true if the user is holding down the specified key.|/RMD|
boolIsMouseButtonPressed ( UserInputType mouseButton )

Returns true if the specified mouse button is currently down.

|RMD member="API:Class/UserInputService/IsMouseButtonPressed"|Returns true if the specified mouse button is currently down.|/RMD|
boolIsNavigationGamepad ( UserInputType gamepadEnum )

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

|RMD member="API:Class/UserInputService/IsNavigationGamepad"|Returns true if the specified Gamepad is allowed to toggle GUI Navigation & Selection.|/RMD|
voidRecenterUserHeadCFrame ( )

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

|RMD member="API:Class/UserInputService/RecenterUserHeadCFrame"|Recenters the UserHeadCFrame to the current location of the VR headset being worn by the user.|/RMD|
voidSetNavigationGamepad ( UserInputType gamepadEnum, bool enabled )

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

|RMD member="API:Class/UserInputService/SetNavigationGamepad"|Sets whether or not the specified Gamepad is allowed to move the GUI navigator around,.|/RMD|
GamepadSupports ( UserInputType gamepadNum, KeyCode gamepadKeyCode )
Returns if specified gamepad supports the corresponding keycode button.
Returns a list of Gamepad UserInputTypes currently connected. If no gamepads are connected, this list will be empty.
Returns an InputObject that describes the device's current acceleration.
Returns an InputObject that describes the device's current gravity vector.
Returns an InputObject and a CFrame that describes the device's current rotation vector.
Returns the currently selected textbox, or nil if none is selected.
Returns true if gamepadNum is connected to the client.
Returns an array of InputObjects for each input on the gamepad with each input's last input state.
Returns a table of InputObjects, whose KeyCodes are currently being pressed.
Returns the most recent UserInputType that the client has used.
Returns an array of InputObjects that corresponds to all the mouse buttons being currently pressed down.
Returns the current change in movement of the mouse, but only if the mouse is locked.
Returns the current screen location of the mouse.
Returns a list of gamepad UserInputTypes in a specific order. It is meant to be iterated over to determine which Gamepad should have navigation control.
Returns the KeyCodes that the connected gamepadNum supports.
Returns a CFrame describing the position & orientation of a specified virtual reality device.
IsKeyDown ( KeyCode keyCode )
Returns true if the user is holding down the specified key.
Returns true if the specified mouse button is currently down.
Returns true if the specified Gamepad is allowed to toggle GUI Navigation & Selection.
Recenters the UserHeadCFrame to the current location of the VR headset being worn by the user.
SetNavigationGamepad ( UserInputType gamepadEnum, bool enabled )
Sets whether or not the specified Gamepad is allowed to move the GUI navigator around,.


Events

Events [toggle]

DeviceAccelerationChanged ( InputObject acceleration )

Fired when a user moves a device that has an accelerometer.

|RMD member="API:Class/UserInputService/DeviceAccelerationChanged"|Fired when a user moves a device that has an accelerometer.|/RMD|
DeviceGravityChanged ( InputObject gravity )

Fired when the force of gravity changes on a device that has an accelerometer.

|RMD member="API:Class/UserInputService/DeviceGravityChanged"|Fired when the force of gravity changes on a device that has an accelerometer.|/RMD|
DeviceRotationChanged ( InputObject rotation, CFrame cframe )

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

|RMD member="API:Class/UserInputService/DeviceRotationChanged"|Fired when a user rotates a device that has a gyroscope.|/RMD|
GamepadConnected ( UserInputType gamepadNum )

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

|RMD member="API:Class/UserInputService/GamepadConnected"|Fires when a gamepad is connected to the client. Passes the gamepadNum of the gamepad that was connected.|/RMD|
GamepadDisconnected ( UserInputType gamepadNum )

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

|RMD member="API:Class/UserInputService/GamepadDisconnected"|Fires when a gamepad is disconnected to the client. Passes the gamepadNum of the gamepad that was disconnected.|/RMD|
InputBegan ( InputObject input, bool gameProcessedEvent )

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

|RMD member="API:Class/UserInputService/InputBegan"|Fired when a user begins interacting via a Human-Computer Interface device.|/RMD|
InputChanged ( InputObject input, bool gameProcessedEvent )

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

|RMD member="API:Class/UserInputService/InputChanged"|Fired when a user changes how they're interacting via a Human-Computer Interface device.|/RMD|
InputEnded ( InputObject input, bool gameProcessedEvent )

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

|RMD member="API:Class/UserInputService/InputEnded"|Fired when a user stops interacting via a Human-Computer Interface device.|/RMD|
JumpRequest ( )

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

|RMD member="API:Class/UserInputService/JumpRequest"|Fires whenever there's a jump request from the client.|/RMD|
LastInputTypeChanged ( UserInputType lastInputType )

Fires when the client's UserInputType is changed.

|RMD member="API:Class/UserInputService/LastInputTypeChanged"|Fires when the client's UserInputType is changed.|/RMD|
TextBoxFocusReleased ( TextBox textboxReleased )

Fired when the client loses focus on a TextBox.

|RMD member="API:Class/UserInputService/TextBoxFocusReleased"|Fired when the client loses focus on a TextBox.|/RMD|
TextBoxFocused ( TextBox textboxFocused )

Fired when the client focuses on a TextBox.

|RMD member="API:Class/UserInputService/TextBoxFocused"|Fired when the client focuses on a TextBox.|/RMD|
TouchEnded ( InputObject touch, bool gameProcessedEvent )

Fired when a user releases their finger from the screen on a TouchEnabled device.

|RMD member="API:Class/UserInputService/TouchEnded"|Fired when a user releases their finger from the screen on a TouchEnabled device.|/RMD|
TouchLongPress ( array<Vector2> touchPositions, UserInputState state, bool gameProcessedEvent )

Fired when a user holds at least one finger for a short amount of time on the same screen position on a TouchEnabled device.

|RMD member="API:Class/UserInputService/TouchLongPress"|Fired when a user holds at least one finger for a short amount of time on the same screen position on a TouchEnabled device.|/RMD|
TouchMoved ( InputObject touch, bool gameProcessedEvent )

Fired when a user moves their finger on a TouchEnabled device.

|RMD member="API:Class/UserInputService/TouchMoved"|Fired when a user moves their finger on a TouchEnabled device.|/RMD|
TouchPan ( array<Vector2> touchPositions, Vector2 totalTranslation, Vector2 velocity, UserInputState state, bool gameProcessedEvent )

Fired when a user drags at least one finger on a TouchEnabled device.

|RMD member="API:Class/UserInputService/TouchPan"|Fired when a user drags at least one finger on a TouchEnabled device.|/RMD|
TouchPinch ( array<Vector2> touchPositions, float scale, float velocity, UserInputState state, bool gameProcessedEvent )

Fired when a user pinches their fingers on a TouchEnabled device.

|RMD member="API:Class/UserInputService/TouchPinch"|Fired when a user pinches their fingers on a TouchEnabled device.|/RMD|
TouchRotate ( array<Vector2> touchPositions, float rotation, float velocity, UserInputState state, bool gameProcessedEvent )

Fired when a user rotates two fingers on a TouchEnabled device.

|RMD member="API:Class/UserInputService/TouchRotate"|Fired when a user rotates two fingers on a TouchEnabled device.|/RMD|
TouchStarted ( InputObject touch, bool gameProcessedEvent )

Fired when a user places their finger on a TouchEnabled device.

|RMD member="API:Class/UserInputService/TouchStarted"|Fired when a user places their finger on a TouchEnabled device.|/RMD|
TouchSwipe ( SwipeDirection swipeDirection, int numberOfTouches, bool gameProcessedEvent )

Fired when a user swipes their fingers on a TouchEnabled device.

|RMD member="API:Class/UserInputService/TouchSwipe"|Fired when a user swipes their fingers on a TouchEnabled device.|/RMD|
TouchTap ( array<Vector2> touchPositions, bool gameProcessedEvent )

Fired when a user taps their finger on a TouchEnabled device.

|RMD member="API:Class/UserInputService/TouchTap"|Fired when a user taps their finger on a TouchEnabled device.|/RMD|
TouchTapInWorld ( Vector2 position, bool processedByUI )

Fires when a mobile tap event is processed in the game world.

|RMD member="API:Class/UserInputService/TouchTapInWorld"|Fires when a mobile tap event is processed in the game world.|/RMD|
UserCFrameChanged ( UserCFrame type, CFrame value )

Fires when the CFrame of a specified VR device changes.

|RMD member="API:Class/UserInputService/UserCFrameChanged"|Fires when the CFrame of a specified VR device changes.|/RMD|
WindowFocusReleased ( )

Fires when the Roblox client loses focus.

|RMD member="API:Class/UserInputService/WindowFocusReleased"|Fires when the Roblox client loses focus.|/RMD|
WindowFocused ( )

Fires when the Roblox client gains focus.

|RMD member="API:Class/UserInputService/WindowFocused"|Fires when the Roblox client gains focus.|/RMD|
Fired when a user moves a device that has an accelerometer.
Fired when the force of gravity changes on a device that has an accelerometer.
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 to the client. Passes the gamepadNum of the gamepad that was disconnected.
InputBegan ( InputObject input, bool gameProcessedEvent )
Fired when a user begins interacting via a Human-Computer Interface device.
InputChanged ( InputObject input, bool gameProcessedEvent )
Fired when a user changes how they're interacting via a Human-Computer Interface device.
InputEnded ( InputObject input, bool gameProcessedEvent )
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 UserInputType is changed.
TextBoxFocusReleased ( TextBox textboxReleased )
Fired when the client loses focus on a TextBox.
TextBoxFocused ( TextBox textboxFocused )
Fired when the client focuses on a TextBox.
TouchEnded ( InputObject touch, bool gameProcessedEvent )
Fired when a user releases their finger from the screen on a TouchEnabled device.
TouchLongPress ( array<Vector2> touchPositions, UserInputState state, bool gameProcessedEvent )
Fired when a user holds at least one finger for a short amount of time on the same screen position on a TouchEnabled device.
TouchMoved ( InputObject touch, bool gameProcessedEvent )
Fired when a user moves their finger on a TouchEnabled device.
TouchPan ( array<Vector2> touchPositions, Vector2 totalTranslation, Vector2 velocity, UserInputState state, bool gameProcessedEvent )
Fired when a user drags at least one finger on a TouchEnabled device.
TouchPinch ( array<Vector2> touchPositions, float scale, float velocity, UserInputState state, bool gameProcessedEvent )
Fired when a user pinches their fingers on a TouchEnabled device.
TouchRotate ( array<Vector2> touchPositions, float rotation, float velocity, UserInputState state, bool gameProcessedEvent )
Fired when a user rotates two fingers on a TouchEnabled device.
TouchStarted ( InputObject touch, bool gameProcessedEvent )
Fired when a user places their finger on a TouchEnabled device.
TouchSwipe ( SwipeDirection swipeDirection, int numberOfTouches, bool gameProcessedEvent )
Fired when a user swipes their fingers on a TouchEnabled device.
TouchTap ( array<Vector2> touchPositions, bool gameProcessedEvent )
Fired when a user taps their finger on a TouchEnabled device.
TouchTapInWorld ( Vector2 position, bool processedByUI )
Fires when a mobile tap event is processed in the game world.
Fires when the CFrame of a specified VR device changes.
Fires when the Roblox client loses focus.
Fires when the Roblox client gains focus.

|RMD member="API:Class/UserInputService"|The UserInputService is a service which is used to detect the type of input available on a user's device via the use of a LocalScript. It allows LocalScripts to perform different actions depending on the device used to provide the best experience for the end user. The purpose of this service is primarily to allow for games to cooperate with multiple forms of available input. |/RMD|



See also