Reference API Roblox

Engine API

Website

Related

Reference API Roblox

UserInputService

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

This class is not replicated. Its interface does not cross the network boundary.
This class is not creatable. Instances of this class cannot be created with Instance.new.
This class is a service. It is a singleton that may be acquired with GetService.
Tags: [NotCreatable, Service, NotReplicated]

Member index 79

HistoryMember
553AccelerometerEnabled: bool
553GamepadEnabled: bool
553GyroscopeEnabled: bool
553KeyboardEnabled: bool
553ModalEnabled: bool
553MouseBehavior: MouseBehavior
553MouseDeltaSensitivity: float
553MouseEnabled: bool
645MouseIcon: ContentId
553MouseIconEnabled: bool
553OnScreenKeyboardPosition: Vector2
553OnScreenKeyboardSize: Vector2
553OnScreenKeyboardVisible: bool
553TouchEnabled: bool
553UserHeadCFrame: CFrame
553VREnabled: bool
462GamepadSupports(gamepadNum: UserInputType, gamepadKeyCode: KeyCode): bool
462GetConnectedGamepads(): Array
483GetDeviceAcceleration(): InputObject
483GetDeviceGravity(): InputObject
638GetDeviceLevel(): DeviceLevel
462GetDeviceRotation(): Tuple
462GetDeviceType(): DeviceType
483GetFocusedTextBox(): TextBox
462GetGamepadConnected(gamepadNum: UserInputType): bool
462GetGamepadState(gamepadNum: UserInputType): Array
645GetImageForKeyCode(keyCode: KeyCode): ContentId
462GetKeysPressed(): Array
462GetLastInputType(): UserInputType
462GetMouseButtonsPressed(): Array
462GetMouseDelta(): Vector2
462GetMouseLocation(): Vector2
462GetNavigationGamepads(): Array
462GetPlatform(): Platform
462GetStringForKeyCode(keyCode: KeyCode): string
462GetSupportedGamepadKeyCodes(gamepadNum: UserInputType): Array
605GetUserCFrame(type: UserCFrame): CFrame
462IsGamepadButtonDown(gamepadNum: UserInputType, gamepadKeyCode: KeyCode): bool
462IsKeyDown(keyCode: KeyCode): bool
462IsMouseButtonPressed(mouseButton: UserInputType): bool
462IsNavigationGamepad(gamepadEnum: UserInputType): bool
573RecenterUserHeadCFrame(): null
573SendAppUISizes(statusBarSize: Vector2, navBarSize: Vector2, bottomBarSize: Vector2, rightBarSize: Vector2): null
573SetNavigationGamepad(gamepadEnum: UserInputType, enabled: bool): null
483DeviceAccelerationChanged(acceleration: InputObject)
483DeviceGravityChanged(gravity: InputObject)
483DeviceRotationChanged(rotation: InputObject, cframe: CFrame)
462GamepadConnected(gamepadNum: UserInputType)
462GamepadDisconnected(gamepadNum: UserInputType)
483InputBegan(input: InputObject, gameProcessedEvent: bool)
483InputChanged(input: InputObject, gameProcessedEvent: bool)
483InputEnded(input: InputObject, gameProcessedEvent: bool)
462JumpRequest()
462LastInputTypeChanged(lastInputType: UserInputType)
462PointerAction(wheel: float, pan: Vector2, pinch: float, gameProcessedEvent: bool)
462StatusBarTapped(position: Vector2)
483TextBoxFocusReleased(textboxReleased: TextBox)
483TextBoxFocused(textboxFocused: TextBox)
650TouchDrag(dragDirection: SwipeDirection, numberOfTouches: int, gameProcessedEvent: bool)
483TouchEnded(touch: InputObject, gameProcessedEvent: bool)
462TouchLongPress(touchPositions: Array, state: UserInputState, gameProcessedEvent: bool)
483TouchMoved(touch: InputObject, gameProcessedEvent: bool)
462TouchPan(touchPositions: Array, totalTranslation: Vector2, velocity: Vector2, state: UserInputState, gameProcessedEvent: bool)
462TouchPinch(touchPositions: Array, scale: float, velocity: float, state: UserInputState, gameProcessedEvent: bool)
462TouchRotate(touchPositions: Array, rotation: float, velocity: float, state: UserInputState, gameProcessedEvent: bool)
483TouchStarted(touch: InputObject, gameProcessedEvent: bool)
462TouchSwipe(swipeDirection: SwipeDirection, numberOfTouches: int, gameProcessedEvent: bool)
462TouchTap(touchPositions: Array, gameProcessedEvent: bool)
462TouchTapInWorld(position: Vector2, processedByUI: bool)
605UserCFrameChanged(type: UserCFrame, value: CFrame)
462WindowFocusReleased()
462WindowFocused()
inherited from Instance
553Archivable: bool
635Capabilities: SecurityCapabilities
553Name: string
553Parent: Instance
635Sandboxed: bool
616UniqueId: UniqueId
576AddTag(tag: string): null
573ClearAllChildren(): null
462Clone(): Instance
573Destroy(): null
486FindFirstAncestor(name: string): Instance
486FindFirstAncestorOfClass(className: string): Instance
486FindFirstAncestorWhichIsA(className: string): Instance
486FindFirstChild(name: string, recursive: bool = false): Instance
486FindFirstChildOfClass(className: string): Instance
486FindFirstChildWhichIsA(className: string, recursive: bool = false): Instance
486FindFirstDescendant(name: string): Instance
563GetActor(): Actor
486GetAttribute(attribute: string): Variant
462GetAttributeChangedSignal(attribute: string): RBXScriptSignal
631GetAttributes(): Dictionary
648GetChildren(): Instances
462GetDebugId(scopeLength: int = 4): string
486GetDescendants(): Array
486GetFullName(): string
641GetStyled(name: string): Variant
576GetTags(): Array
576HasTag(tag: string): bool
486IsAncestorOf(descendant: Instance): bool
486IsDescendantOf(ancestor: Instance): bool
580IsPropertyModified(name: string): bool
573Remove(): null
576RemoveTag(tag: string): null
580ResetPropertyToDefault(name: string): null
573SetAttribute(attribute: string, value: Variant): null
462WaitForChild(childName: string, timeOut: double): Instance
648children(): Instances
553clone(): Instance
573destroy(): null
553findFirstChild(name: string, recursive: bool = false): Instance
648getChildren(): Instances
553isDescendantOf(ancestor: Instance): bool
573remove(): null
462AncestryChanged(child: Instance, parent: Instance)
462AttributeChanged(attribute: string)
462ChildAdded(child: Instance)
462ChildRemoved(child: Instance)
462DescendantAdded(descendant: Instance)
462DescendantRemoving(descendant: Instance)
500Destroying()
553childAdded(child: Instance)
inherited from Object
647ClassName: string
647className: string
647GetPropertyChangedSignal(property: string): RBXScriptSignal
647IsA(className: string): bool
650isA(className: string): bool
647Changed(property: string)

Removed member index 10

HistoryMember
220InCameraGesture: bool
240IsVREnabled: bool
220OverrideMouseIconEnabled: bool
118TouchControlsEnabled: bool
230IsLuaTouchControls(): bool
230IsStudioTouchEmulationEnabled(): bool
230RotateCamera(positionDelta: Vector2): void
230ZoomCamera(zoomDelta: float): void
230ProcessedEvent(inputObject: Instance, processed: bool)

Description

UserInputService is a service used to detect and capture the different types of input available on a user's device.

The primary purpose of this service is to allow for experiences 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, 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 or a ModuleScript required by a LocalScript. As UserInputService is client-side only, users in the game can only detect their own input - and not the input of others.

See also ContextActionService, a service which allows you to bind functions to multiple user inputs.

History 324

Members 79

AccelerometerEnabled

TypeDefault
bool

This property describes whether the user's device has an accelerometer

An accelerometer is a component found in most mobile devices that measures acceleration (change in speed).

For example, the following code snippet demonstrates how to check if the user's device has an accelerometer.

1
2
3
4
5
6
7
8
local UserInputService = game:GetService("UserInputService")

local accelerometerEnabled = UserInputService.AccelerometerEnabled
if accelerometerEnabled then
	print("Accelerometer enabled!")
else
	print("Accelerometer not enabled!")
end

If the device has an enabled accelerometer, you can get it's current acceleration by using the UserInputService:GetDeviceAcceleration() function or track when the device's acceleration changes by using the UserInputService.DeviceAccelerationChanged event.

As UserInputService is client-side only, this property can only be used in a LocalScript.

This property is not replicated. Its interface does not cross the network boundary.
This property is read-only. Its value can be read, but it cannot be modified.

History 4

Tags: [ReadOnly, NotReplicated]

DeviceAccelerationChanged

Parameters (1)
accelerationInputObject

The DeviceAccelerationChanged event fires when a user moves a device that has an accelerometer.

An accelerometer is a component found in most mobile devices that measures acceleration (change in speed).

To determine whether a user's device has an accelerometer enabled, seeUserInputService.AccelerometerEnabled.

This event can be used to track the movement of a device that has an accelerometer. A sample usage includes moving the player character when a mobile device accelerates.

Additionally, this event can be used along with UserInputService:GetDeviceAcceleration() to determine the current movement of a user's device if the device has an accelerometer.

This event only fires locally - which means that only the player whose device moves can use the event and it will only work in a LocalScript.

History 3

DeviceGravityChanged

Parameters (1)
gravityInputObject

The UserInputService.DeviceGravityChanged event fires when the device's gravity Vector3 changes on a device that has an accelerometer.

A device's gravity vector represent the force of gravity on each of the device's X, Y, and Z axes. While gravity never changes, the force it exerts on each axis changes when the device rotates and changes orientation. The force value exerted on each axis is a unit vector ranging from -1 to 1.

An accelerometer is a component found in most mobile devices that measures acceleration (change in speed).

This event can be used to determine the real-world direction of the force of gravity on a user's device. This even can then be used to simulate the force of gravity on a user's device within the game, such as on in-game objects (see example below).

To check if a user's device has an enabled accelerometer, see UserInputService.AccelerometerEnabled. If the device has an enabled accelerometer, you can use the UserInputService:GetDeviceGravity() function to get the current force of gravity on the user's device.

History 3

DeviceRotationChanged

Parameters (2)
rotationInputObject
cframeCFrame

The DeviceRotationChanged event fires when a user rotates a device that has a gyroscope.

A gyroscope is a component found in most mobile devices that detects orientation and rotational speed.

The event is useful when tracking the orientation of the device and how changes as the user rotates their device. To determine the current device rotation, you can use the UserInputService:GetDeviceRotation() function.

To check if a user's device has an enabled gyroscope, and that this event will fire, see UserInputService.GyroscopeEnabled.

This event only fires when the Roblox client window is in focus. For example, inputs will not be captured when the window is minimized.

History 3

GamepadConnected

Parameters (1)
gamepadNumUserInputType

The GamepadConnected event fires when a gamepad is connected to the client.

Since a Roblox game supports multiple controllers, this event is useful when paired with the UserInputService.GamepadDisconnected event to track which controllers/gamepads are active. You can also use UserInputService:GetConnectedGamepads() to find the correct gamepad to use.

The following example demonstrates a usage example of a tracking when a gamepad is connected to the client.

1
2
3
4
5
6
7
local UserInputService = game:GetService("UserInputService")

local function GamepadConnected(gamepad)
	print("Player has plugged controller: " .. tostring(gamepad))
end)

UserInputService.GamepadConnected:Connect(GamepadConnected)

If you want to see which devices are connected, you can use the UserInputService:GetConnectedGamepads() function.

As this event fires locally, it can only be used in a LocalScript.

See also:

History 2

GamepadDisconnected

Parameters (1)
gamepadNumUserInputType

The GamepadDisconnected event fires when a gamepad is disconnected.

Since a Roblox game supports multiple controllers, this event is useful when paired with the UserInputService.GamepadConnected event to track which controllers/gamepads are active. You can also use UserInputService:GetConnectedGamepads() to find the correct gamepad to use.

The following example demonstrates a usage example of a tracking when a gamepad is disconnected from the client.

1
2
3
4
5
6
7
local UserInputService = game:GetService("UserInputService")

local function GamepadDisconnected(gamepad)
	print("Player has unplugged controller: " .. tostring(gamepad))
end)

UserInputService.GamepadDisconnected:Connect(GamepadDisconnected)

As this event fires locally, it can only be used in a LocalScript.

See also:

History 2

GamepadEnabled

TypeDefault
bool
This property is not replicated. Its interface does not cross the network boundary.
This property is read-only. Its value can be read, but it cannot be modified.

History 6

Tags: [ReadOnly, NotReplicated]

GamepadSupports

Parameters (2)
gamepadNumUserInputType
gamepadKeyCodeKeyCode
Returns (1)
bool

This function returns whether the given UserInputType gamepad supports a button corresponding with the given KeyCode. This function is used to determine valid gamepad inputs.

To determine which UserInputType gamepads are connected, use UserInputService:GetConnectedGamepads().

As UserInputService is client-side only, this function can only be used in a LocalScript.

See also:

History 2

GetConnectedGamepads

Parameters (0)
No parameters.
Returns (1)
Array

This function returns an array of UserInputType gamepads currently connected. If no gamepads are connected, this array will be empty. Additionally, it only returns UserInputType objects that are gamepads. For instance, this event will return a connected Gamepad1 object but not a Keyboard object.

For example, the following code snippet retrieves the connected gamepads and stores them in a variable named connectedGamepads.

1
2
local UserInputService = game:GetService("UserInputService")
local connectedGamepads = UserInputService:GetConnectedGamepads()

To check if a specific gamepad is connected, use UserInputService:GetGamepadConnected().

As UserInputService is client-side only, this function can only be used in a LocalScript.

See also:

History 2

GetDeviceAcceleration

Parameters (0)
No parameters.
Returns (1)
InputObject

The GetDeviceAcceleration function determines the current acceleration of the user's device. It returns an InputObject that describes the device's current acceleration.

In order for this to work, the user's device must have an enabled accelerometer. To check if a user's device has an enabled accelerometer, you can check the UserInputService.AccelerometerEnabled property.

If you want to track when the user's device's acceleration changes instead, you can use the UserInputService.DeviceAccelerationChanged event.

Since it only fires locally, it can only be used in a LocalScript.

History 3

GetDeviceGravity

Parameters (0)
No parameters.
Returns (1)
InputObject

This function returns an InputObject describing the device's current gravity vector.

The gravity vector is determined by the device's orientation relative to the real-world force of gravity. For instance, if a device is perfectly upright (portrait), the gravity vector is Vector3.new(0, 0, -9.18). If the left side of the device is pointing down, the vector is Vector3.new(9.81, 0, 0). Finally, if the back of the device is pointing down, the vector is Vector3.new(0, -9.81, 0).

This function might be used to enable the user's device to impact or control gravity within the game or move in-game objects such as a ball.

Gravity is only tracked for players using a device with an enabled gyroscope - such as a mobile device.

To check if a user's device has an enabled gyroscope, check the value of UserInputService.GyroscopeEnabled. If the device has an enabled gyroscope, you can also use the UserInputService.DeviceGravityChanged event to track when force of gravity on the user's device changes.

As UserInputService is client-side only, this function can only be used in a LocalScript.

History 3

GetDeviceLevel

Parameters (0)
No parameters.
Returns (1)
DeviceLevel

History 1

GetDeviceRotation

Parameters (0)
No parameters.
Returns (1)
Tuple

This function returns an InputObject and a CFrame describing the device's current rotation vector.

This is fired with an InputObject. The Position property of the input object is a Enum.InputType.Gyroscope that tracks the total rotation in each local device axis.

Device rotation can only be tracked on devices with a gyroscope.

As this function fires locally, it can only be used in a LocalScript.

History 2

GetDeviceType

Parameters (0)
No parameters.
Returns (1)
DeviceType

History 2

GetFocusedTextBox

Parameters (0)
No parameters.
Returns (1)
TextBox

This function returns the TextBox the client is currently focused on. A TextBox can be manually selected by the user, or selection can be forced using the TextBox:CaptureFocus() function. If no TextBox is selected, this function will return nil.

As UserInputService is client-side only, this function can only be used in a LocalScript.

See also:

History 3

GetGamepadConnected

Parameters (1)
gamepadNumUserInputType
Returns (1)
bool

This function returns whether a gamepad with the given UserInputType is connected to the client.

This can be used to check if a specific gamepad, such as 'Gamepad1' is connected to the client's device.

To retrieve a list of all connected gamepads, use UserInputService:GetConnectedGamepads().

As UserInputService is client-side only, this function can only be used in a LocalScript.

See also:

History 2

GetGamepadState

Parameters (1)
gamepadNumUserInputType
Returns (1)
Array

History 2

GetImageForKeyCode

Parameters (1)
keyCodeKeyCode
Returns (1)
ContentId

This method takes the requested KeyCode and returns the associated image for the currently connected gamepad device (limited to Xbox, PlayStation and Windows). This means that if the connected controller is an Xbox One controller, the user sees Xbox assets. Similarly, if the connected device is a PlayStation controller, the user sees PlayStation assets. If you want to use custom assets, see GetStringForKeyCode().

History 2

GetKeysPressed

Parameters (0)
No parameters.
Returns (1)
Array

This function returns an array of InputObjects associated with the keys currently being pressed down.

This array can be iterated through to determine which keys are currently being pressed, using the InputObject.KeyCode values.

To check if a specific key is being pressed, use UserInputService:IsKeyDown().

As UserInputService is client-side only, this function can only be used in a LocalScript.

History 4

GetLastInputType

Parameters (0)
No parameters.
Returns (1)
UserInputType

This function returns 'Enum.UserInputType` associated with the user's most recent input.

For example, if the user's previous input had been pressing the spacebar, the UserInputType returned would be 'Keyboard'.

The UserInputService.LastInputTypeChanged event can be used to track when the last UserInputType used by the user changes.

As UserInputService is client-side only, this function can only be used in a LocalScript.

History 3

GetMouseButtonsPressed

Parameters (0)
No parameters.
Returns (1)
Array

This function returns an array of InputObjects corresponding to the mouse buttons currently being pressed down.

Mouse buttons that are tracked by this function include:

NameDescription
MouseButton1The left mouse button.
MouseButton2The right mouse button.
MouseButton3The middle mouse button.

If the user is not pressing any mouse button down when the function is called, it will return an empty array.

As UserInputService is client-side only, this function can only be used in a LocalScript.

History 2

GetMouseDelta

Parameters (0)
No parameters.
Returns (1)
Vector2

This function returns the change, in pixels, of the position of the player's Mouse in the last rendered frame as a Vector2. This function only works if the mouse has been locked using the UserInputService.MouseBehavior property. If the mouse has not been locked, the returned Vector2 values will be zero.

The sensitivity of the mouse, determined in the client's settings and UserInputService.MouseDeltaSensitivity, will influence the result.

As UserInputService is client-side only, this function can only be used in a LocalScript.

History 2

GetMouseLocation

Parameters (0)
No parameters.
Returns (1)
Vector2

This function returns a Vector2 representing the current screen location of the player's Mouse in pixels relative to the top left corner. This does not account for the GUI inset.

If the location of the mouse pointer is offscreen or the player's device does not have a mouse, the returned value will be undetermined.

As UserInputService is client-side only, this function can only be used in a LocalScript.

History 2

GetNavigationGamepads

Parameters (0)
No parameters.
Returns (1)
Array

This function returns an array of gamepad UserInputTypes that are connected and enabled for GUI navigation. This list is in descending order of priority, meaning it can be iterated over to determine which gamepad should have navigation control.

Whether a connected gamepad is a navigation gamepad only determines which gamepad(s) control the navigation GUIs. This does not influence navigation controls.

Since UserInputService is client-side only, this function can only be used in a LocalScript.

See also:

History 2

GetPlatform

Parameters (0)
No parameters.
Returns (1)
Platform

History 2

GetStringForKeyCode

Parameters (1)
keyCodeKeyCode
Returns (1)
string

GetStringForKeyCode returns a string representing a key the user should press in order to input a given KeyCode, keeping in mind their keyboard layout. For key codes that require some modifier to be held, this function returns the key to be pressed in addition to the modifier. See the examples below for further explanation.

When using Roblox with a non‑QWERTY keyboard layout, key codes are mapped to equivalent QWERTY positions. For example, pressing A on an AZERTY keyboard results in KeyCode.Q. This mapping can lead to mismatched information on experience UI elements. For example, "Press M to open the map" is inaccurate on an AZERTY keyboard; it would need to be "Press ? to open the map" which is in the same position as M on QWERTY. This function solves this issue by providing the actual key to be pressed while using non‑QWERTY keyboard layouts.

local UserInputService = game:GetService("UserInputService")

local textLabel = script.Parent
local mapKey = Enum.KeyCode.M
textLabel.Text = "Press " .. UserInputService:GetStringForKeyCode(mapKey) .. " to open the map"

Examples on QWERTY Keyboard

KeyCodeReturn Value
KeyCode.QQ
KeyCode.WW
KeyCode.Equals=
KeyCode.At2 because @ is typed with Shift2

Examples on AZERTY Keyboard

KeyCodeReturn Value
KeyCode.QA
KeyCode.WZ
KeyCode.Equals=
KeyCode.AtÉ

Gamepad Usage

GetStringForKeyCode() returns the string mapping for the KeyCode for the most recently connected gamepad. If the connected controller is not supported, the function returns the default string conversion for the requested key code.

The following example shows how you can map custom assets for ButtonA:

local UserInputService = game:GetService("UserInputService")

local imageLabel = script.Parent
local key = Enum.KeyCode.ButtonA

local mappings = {
  ButtonA = "rbxasset://BUTTON_A_ASSET",  -- Replace with the desired ButtonA asset
  ButtonCross = "rbxasset://BUTTON_CROSS_ASSET"  -- Replace with the desired ButtonCross asset
}

local mappedKey = UserInputService:GetStringForKeyCode(key)
local image = mappings[mappedKey]

imageLabel.Image = image

Gamepad Mappings

The directional pad key codes do not have any differences based on device. KeyCode.ButtonSelect has slightly different behavior in some cases. Use both PlayStation mappings to ensure users see the correct buttons.

KeyCodePlayStation Return ValueXbox Return Value
KeyCode.ButtonAButtonCrossButtonA
KeyCode.ButtonBButtonCircleButtonB
KeyCode.ButtonXButtonSquareButtonX
KeyCode.ButtonYButtonTriangleButtonY
KeyCode.ButtonL1ButtonL1ButtonLB
KeyCode.ButtonL2ButtonL2ButtonLT
KeyCode.ButtonL3ButtonL3ButtonLS
KeyCode.ButtonR1ButtonR1ButtonRB
KeyCode.ButtonR2ButtonR2ButtonRT
KeyCode.ButtonR3ButtonR3ButtonRS
KeyCode.ButtonStartButtonOptionsButtonStart
KeyCode.ButtonSelectButtonTouchpad and ButtonShareButtonSelect

System Images for KeyCodes

When using a KeyCode that may be better represented as an image, such as for an ImageLabel in a user interface, you can use the following legacy icons. However, it's recommended that you use GetImageForKeyCode() as a more modern, cross‑platform method to retrieve Xbox and PlayStation controller icons.

KeyCodeImageAsset ID
KeyCode.ButtonXrbxasset://textures/ui/Controls/xboxX.png
KeyCode.ButtonYrbxasset://textures/ui/Controls/xboxY.png
KeyCode.ButtonArbxasset://textures/ui/Controls/xboxA.png
KeyCode.ButtonBrbxasset://textures/ui/Controls/xboxB.png
KeyCode.DPadLeftrbxasset://textures/ui/Controls/dpadLeft.png
KeyCode.DPadRightrbxasset://textures/ui/Controls/dpadRight.png
KeyCode.DPadUprbxasset://textures/ui/Controls/dpadUp.png
KeyCode.DPadDownrbxasset://textures/ui/Controls/dpadDown.png
KeyCode.ButtonSelectrbxasset://textures/ui/Controls/xboxView.png
KeyCode.ButtonStartrbxasset://textures/ui/Controls/xboxmenu.png
KeyCode.ButtonL1rbxasset://textures/ui/Controls/xboxLB.png
KeyCode.ButtonR1rbxasset://textures/ui/Controls/xboxRB.png
KeyCode.ButtonL2rbxasset://textures/ui/Controls/xboxLT.png
KeyCode.ButtonR2rbxasset://textures/ui/Controls/xboxRT.png
KeyCode.ButtonL3rbxasset://textures/ui/Controls/xboxLS.png
KeyCode.ButtonR3rbxasset://textures/ui/Controls/xboxRS.png
KeyCode.Thumbstick1rbxasset://textures/ui/Controls/xboxLSDirectional.png
KeyCode.Thumbstick2rbxasset://textures/ui/Controls/xboxRSDirectional.png
KeyCode.Backspacerbxasset://textures/ui/Controls/backspace.png
KeyCode.Returnrbxasset://textures/ui/Controls/return.png
KeyCode.LeftShiftrbxasset://textures/ui/Controls/shift.png
KeyCode.RightShiftrbxasset://textures/ui/Controls/shift.png
KeyCode.Tabrbxasset://textures/ui/Controls/tab.png
KeyCode.Apostropherbxasset://textures/ui/Controls/apostrophe.png
KeyCode.Commarbxasset://textures/ui/Controls/comma.png
KeyCode.Backquoterbxasset://textures/ui/Controls/graveaccent.png
KeyCode.Periodrbxasset://textures/ui/Controls/period.png
KeyCode.Spacerbxasset://textures/ui/Controls/spacebar.png

History 2

GetSupportedGamepadKeyCodes

Parameters (1)
gamepadNumUserInputType
Returns (1)
Array

This function returns an array of KeyCodes that the gamepad associated with the given UserInputType supports.

This function can be used to determine which KeyCodes are supported and not supported by a connected gamepad. To determine if a specific KeyCode is supported, use UserInputService:GamepadSupports().

If called on a non existent, or non connected, gamepad, this function will return an empty array.

As UserInputService is client-side only, this function can only be used in a LocalScript.

See also:

History 2

GetUserCFrame

Parameters (1)
typeUserCFrame
Returns (1)
CFrame

The UserInputService:GetUserCFrame() function returns a CFrame describing the position and orientation of a specified UserCFrame virtual reality (VR) device. If the specified device is not connected, the function returns CFrame.new().

For example, the code snippet below prints the CFrame of the user's VR headset.

1
2
3
4
local UserInputService = game:GetService("UserInputService")
local cframe = UserInputService:GetUserCFrame(Enum.UserCFrame.Head)

print(cframe)

By using the function, players can implement features such as re-positioning the user's in-game character corresponding to the location of a connected VR device. This can be done by changing the CFrame of the user's in-game body parts to match the CFrame of the specified VR device using UserCFrame and CFrame value arguments passed by the event.

See also:

As this event only fires locally, it can only be used in a LocalScript.

This function is deprecated. It exists only for backward compatibility, and should not be used for new work.

History 4

Tags: [Deprecated]

GyroscopeEnabled

TypeDefault
bool

This property describes whether the user's device has a gyroscope.

A gyroscope is a component found in most mobile devices that detects orientation and rotational speed.

If a user's device has a gyroscope, you can use incorporate it into your game using the UserInputService:GetDeviceRotation() function and UserInputService.DeviceRotationChanged event.

1
2
3
4
5
6
7
8
local UserInputService = game:GetService("UserInputService")

local gyroIsEnabled = UserInputService.GyroscopeEnabled
if gyroIsEnabled then
	print("Gyroscope is enabled!")
else
	print("Gyroscope is not enabled!")
end

As UserInputService is client-side only, this property can only be used in a LocalScript.

This property is not replicated. Its interface does not cross the network boundary.
This property is read-only. Its value can be read, but it cannot be modified.

History 4

Tags: [ReadOnly, NotReplicated]

InputBegan

Parameters (2)
inputInputObject
gameProcessedEventbool

The InputBegan event fires when a user begins interacting via a Human-Computer Interface device (mouse button down, touch begin, keyboard button down, etc.).

It can be used to track the beginning of user interaction, such as when a user first interacts with a GUI element, a gamepad, etc. It does not capture mouse wheel movements.

This event can be used along with UserInputService.InputChanged and UserInputService.InputEnded to track when user input begins, changes, and ends.

This event only fires when the Roblox client window is in focus. For example, inputs will not be captured when the window is minimized.

As this event only fires locally, it can only be used in a LocalScript.

History 6

InputChanged

Parameters (2)
inputInputObject
gameProcessedEventbool

The InputChanged event fires when a user changes how they're interacting via a Human-Computer Interface device (mouse button down, touch begin, keyboard button down, etc).

To ignore events that are automatically handled by Roblox, like scrolling in a ScrollingFrame, check the gameProcessedEvent argument is false. This event can be used along with UserInputService.InputBegan and UserInputService.InputEnded to track when user input begins, changes, and ends.

This event only fires when the Roblox client window is in focus. For example, inputs will not be captured when the window is minimized.

As this event only fires locally, it can only be used in a LocalScript.

History 6

InputEnded

Parameters (2)
inputInputObject
gameProcessedEventbool

The InputEnded event fires when a user stops interacting via a Human-Computer Interface device (mouse button down, touch begin, keyboard button down, etc). This is useful when tracking when a user releases a keyboard key, mouse button, touchscreen input, etc.

This event can be used along with UserInputService.InputBegan and UserInputService.InputChanged to track when user input begins, changes, and ends.

This event only fires when the Roblox client window is in focus. For example, inputs will not be captured when the window is minimized.

As this event only fires locally, it can only be used in a LocalScript.

History 6

IsGamepadButtonDown

Parameters (2)
gamepadNumUserInputType
gamepadKeyCodeKeyCode
Returns (1)
bool

This function checks if a particular button is pressed on a particular gamepad. It returns true if the gamepad has the specified button pressed down, otherwise it returns false.

Valid UserInputTypes

The specified gamepad should be one of the following UserInputType enum values:

Name
Enum.UserInputType.Gamepad1-8

Valid KeyCodes

The specified button should be one of the following KeyCodes enum values:

Name
Enum.KeyCode.ButtonX
Enum.KeyCode.ButtonY
Enum.KeyCode.ButtonA
Enum.KeyCode.ButtonB
Enum.KeyCode.ButtonR1
Enum.KeyCode.ButtonL1
Enum.KeyCode.ButtonR2
Enum.KeyCode.ButtonL2
Enum.KeyCode.ButtonR3
Enum.KeyCode.ButtonL3
Enum.KeyCode.ButtonStart
Enum.KeyCode.ButtonSelect
Enum.KeyCode.DPadLeft
Enum.KeyCode.DPadRight
Enum.KeyCode.DPadUp
Enum.KeyCode.DPadDown

This can be used to check whether a specific button, such as A, is being held down. For example:

1
2
3
4
5
6
local UserInputService = game:GetService("UserInputService")

local button = Enum.KeyCode.ButtonA
local gamepad = Enum.UserInputType.Gamepad1

local isButtonHeld = UserInputService:IsGamepadButtonDown(gamepad, button)

Since UserInputService is client-side only, this function can only be used in a LocalScript.

See also:

History 2

IsKeyDown

Parameters (1)
keyCodeKeyCode
Returns (1)
bool

This function returns whether the user is holding down the key associated with the given KeyCode. It returns true if the specified key is pressed or false if it is not pressed.

This can be used to check if a specific key, such as the space bar, is being pressed. For example:

1
2
3
local UserInputService = game:GetService("UserInputService")

local spaceHeld = UserInputService:IsKeyDown(Enum.KeyCode.Space)

To retrieve a list of all keys pressed by the user, use the UserInputService:GetKeysPressed() function.

Since UserInputService is client-side only, this function can only be used in a LocalScript.

See also:

History 4

IsMouseButtonPressed

Parameters (1)
mouseButtonUserInputType
Returns (1)
bool

This function takes a mouse button UserInputType and returns a bool that indicates whether it is currently pressed.

The mouse button checked depends on the UserInputType value passed to the function as an argument. For example:

1
2
3
local UserInputService = game:GetService("UserInputService")

local pressed = UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)

Since UserInputService is client-side only, this function can only be used in a LocalScript."

History 2

IsNavigationGamepad

Parameters (1)
gamepadEnumUserInputType
Returns (1)
bool

This function returns true if the specified UserInputType gamepad is allowed to control Navigation and Selection GUIs.

If you want to set a navigation gamepad, you can use UserInputService:SetNavigationGamepad(). You can also use UserInputService:GetNavigationGamepads() to get a list of all navigation gamepads.

For example, the code below checks if the gamepad1 is as a navigation gamepad:

1
2
3
4
5
6
7
local UserInputService = game:GetService("UserInputService")

if UserInputService:IsNavigationGamepad(UserInputType.Gamepad1) then
	print("Gamepad is a navigation gamepad!")
else
	print("Gamepad is not a navigation gamepad!")
end

A list of all connected gamepads, regardless of navigation can be retrieved using`UserInput/GetConnectedGamepads.

Since UserInputService is client-side only, this function can only be used in a LocalScript.

See also:

History 2

JumpRequest

Parameters (0)
No parameters.

The UserInputService JumpRequest event fires when there is a jump request from the client, for example when the client presses the spacebar or jump button on mobile.

This event fires whenever the user tries to make their Player.Character jump. Default behavior responds to a jump request by setting the player's Humanoid.Jump property to true, which makes the player's character jump.

The event can be used to track every time a player wants to jump. Instead of using it to make a player jump, this should be used to change default jump behavior - such as disabling jumping.

For example, the code below prints "Jump" every time the player sends a jump request.

1
2
3
4
5
6
7
local UserInputService = game:GetService("UserInputService")

function onJumpRequest()
	print("Jump!")
end

UserInputService.JumpRequest:Connect(onJumpRequest)

Since this event fires multiple times for a single jump request, using a debounce is suggested.

If you would like to connect keys or buttons to other actions, consider using events such as UserInputService:GetKeysPressed() and UserInputService.InputBegan or the ContextActionService.

As this event only fires locally, it can only be used in a LocalScript.

History 3

KeyboardEnabled

TypeDefault
bool

This property describes whether the user's device has a keyboard available. This property is true when the user's device has an available keyboard, and false when it does not.

It can be used to determine whether the user has an available keyboard - which can be important if you want to check if you can use UserInputService:IsKeyDown() or UserInputService:GetKeysPressed() to check for keyboard input.

As UserInputService is client-side only, this property can only be used in a LocalScript.

This property is not replicated. Its interface does not cross the network boundary.
This property is read-only. Its value can be read, but it cannot be modified.

History 6

Tags: [ReadOnly, NotReplicated]

LastInputTypeChanged

Parameters (1)
lastInputTypeUserInputType

The UserInputService.LastInputTypeChanged event fires whenever the client changes how they are interacting via a Human-Computer Interface device. (i.e. from MouseMovement to MouseWheel or from Thumbstick1 to Thumbstick2).

To get the value of the last input type, regardless of whether it has changed, you can use the UserInputService:GetLastInputType() function.

As this event only fires locally, it can only be used in a LocalScript.

History 3

ModalEnabled

TypeDefault
bool

The ModalEnabled property determines whether character controls are hidden on TouchEnabled devices. By default, this property is false and controls are visible.

This property will only work when used in a LocalScript running for the player whose character controls are to be hidden.

Even if mobile controls are hidden for a player on a touch‑enabled device, other events such as InputBegan and TouchSwipe can still be used to process other forms of input.

This property is deprecated. It exists only for backward compatibility, and should not be used for new work. TouchControlsEnabled should be used instead.

History 6

Tags: [Deprecated]

MouseBehavior

TypeDefault
MouseBehavior

This property sets how the user's mouse behaves based on the MouseBehavior Enum. The default value is Enum.MouseBehavior.Default.

It can be set to three values:

  1. Default: The mouse moves freely around the user's screen.
  2. LockCenter: The mouse is locked, and cannot move from, the center of the user's screen.
  3. LockCurrentPosition: The mouse is locked, and cannot move from, it's current position on the user's screen at the time of locking.

The value of this property does not affect the sensitivity of events tracking mouse movement. For example, GetMouseDelta returns the same Vector2 screen position in pixels regardless of whether the mouse is locked or able to move freely around the user's screen. As a result, default scripts like those controlling the camera are not impacted by this property.

This property is overridden if a GuiButton with Modal enabled is GuiButton.Visible unless the player's right mouse button is down.

Note that, if the mouse is locked, UserInputService.InputChanged will still fire when the player moves the mouse and will pass in the Delta that the mouse attempted to move by. Additionally, if the player is kicked from the game, the mouse will be forcefully unlocked.

As UserInputService is client-side only, this property can only be used in a LocalScript.

History 4

MouseDeltaSensitivity

TypeDefault
float

This property determines the sensitivity of the user's Mouse.

The sensitivity determines the extent to which a movement of the physical mouse translates to a movement of the mouse in-game. This can be used to adjusted how sensitive events tracking mouse movement, like GetMouseDelta, are to mouse movement.

This property does not affect the movement of the mouse icon. Nor does it affect the Camera Sensitivity setting found in the Settings tab of the client's Settings menu, which also adjusts the sensitivity of events tracking mouse movement.

This property has a maximum value of 10 and a minimum value of 0. A lower value corresponds to lower sensitivity, and a higher value to higher sensitivity.

When sensitivity is 0, events that track the mouse's movement will still fire but all parameters and properties indicating the change in mouse position will return Vector2.new(), or Vector3.new() in the case of InputObject.Delta. For example, GetMouseDelta will always return (0, 0).

This property is not replicated. Its interface does not cross the network boundary.

History 4

Tags: [NotReplicated]

MouseEnabled

TypeDefault
bool

This property describes whether the user's device has a mouse available. This property is true when the user's device has an available mouse, and false when it does not.

1
2
3
4
5
6
7
local UserInputService = game:GetService("UserInputService")

if UserInputService.MouseEnabled then
	print("The user's device has an available mouse!")
else
	print("The user's device does not have an available mouse!")
end

It is important to check this before using UserInputService mouse functions such as UserInputService:GetMouseLocation().

As UserInputService is client-side only, this property can only be used in a LocalScript.

See also:

This property is not replicated. Its interface does not cross the network boundary.
This property is read-only. Its value can be read, but it cannot be modified.

History 6

Tags: [ReadOnly, NotReplicated]

MouseIcon

TypeDefault
ContentId

The MouseIcon property determines the image used as the pointer. If blank, a default arrow is used. While the cursor hovers over certain UI objects such as an ImageButton, TextButton, TextBox, or ProximityPrompt, this image will be overridden and temporarily ignored.

To hide the cursor entirely, do not use a transparent image. Instead, set UserInputService.MouseIconEnabled to false.

History 2

MouseIconEnabled

TypeDefault
bool

This property determines whether the Mouse icon is visible When true the mouse's icon is visible, when false it is not.

For example, the code snippet below hides the mouse's icon.

1
2
3
local UserInputService = game:GetService("UserInputService")

UserInputService.MouseIconEnabled = false

As UserInputService is client-side only, this property can only be used in a LocalScript.

History 4

OnScreenKeyboardPosition

TypeDefault
Vector2

This property describes the position of the on-screen keyboard in pixels. The keyboard's position is Vector2.new(0, 0) when it is not visible.

As UserInputService is client-side only, this property can only be used in a LocalScript, or a Script with RunContext set to RunContext.Client.

See also OnScreenKeyboardVisible and OnScreenKeyboardSize.

This property is not replicated. Its interface does not cross the network boundary.
This property is read-only. Its value can be read, but it cannot be modified.

History 4

Tags: [ReadOnly, NotReplicated]

OnScreenKeyboardSize

TypeDefault
Vector2

This property describes the size of the on-screen keyboard in pixels. The keyboard's size is Vector2.new(0, 0) when it is not visible.

As UserInputService is client-side only, this property can only be used in a LocalScript, or a Script with RunContext set to RunContext.Client.

See also OnScreenKeyboardVisible and OnScreenKeyboardPosition.

This property is not replicated. Its interface does not cross the network boundary.
This property is read-only. Its value can be read, but it cannot be modified.

History 4

Tags: [ReadOnly, NotReplicated]

OnScreenKeyboardVisible

TypeDefault
bool

This property describes whether an on-screen keyboard is currently visible on the user's screen.

As UserInputService is client-side only, this property can only be used in a LocalScript, or a Script with RunContext set to RunContext.Client.

See also OnScreenKeyboardSize and OnScreenKeyboardPosition.

This property is not replicated. Its interface does not cross the network boundary.
This property is read-only. Its value can be read, but it cannot be modified.

History 4

Tags: [ReadOnly, NotReplicated]

PointerAction

Parameters (4)
wheelfloat
panVector2
pinchfloat
gameProcessedEventbool

PointerAction fires when the user performs a specific pointer action. In particular, scrolling the mouse wheel.

History 2

RecenterUserHeadCFrame

Parameters (0)
No parameters.
Returns (1)
null

This function recenters the CFrame of the VR headset to the current orientation of the headset worn by the user. This means that the headset's current orientation is set to CFrame.new().

Use this function to move the headset CFrame to the center of the play area if it seems to be at a weird offset.

This behaves identically to the VRService function, VRService:RecenterUserHeadCFrame().

Since UserInputService is client-side only, this function can only be used in a LocalScript.

History 3

SendAppUISizes

Parameters (4)
statusBarSizeVector2
navBarSizeVector2
bottomBarSizeVector2
rightBarSizeVector2
Returns (1)
null

History 4

SetNavigationGamepad

Parameters (2)
gamepadEnumUserInputType
enabledbool
Returns (1)
null

The SetNavigationGamepad function sets whether the specified UserInputType gamepad can move the GUI navigator. A gamepad that is allowed to move the GUI navigator is considered a navigation gamepad.

If the enabled argument is passed as true, the Gamepad can move the GUI navigator. If the argument is false, the Gamepad can not move the GUI navigator.

If you want to check if a specified Gamepad is a set to be a navigation gamepad, you can use the UserInputService:IsNavigationGamepad() function. You can also use the UserInputService:GetNavigationGamepads() to retrieve a list of all navigation gamepads.

Since UserInputService is client-side only, this function can only be used in a LocalScript.

See also:

History 3

StatusBarTapped

Parameters (1)
positionVector2

History 2

TextBoxFocusReleased

Parameters (1)
textboxReleasedTextBox

The TextBoxFocusReleased event fires when a client loses focus on a TextBox - typically when a client stops text entry into a TextBox by pressing return or clicking/touching elsewhere on the screen.

For example, the code below prints the name of the TextBox losing focus when the event fires.

1
2
3
4
5
6
7
local UserInputService = game:GetService("UserInputService")

function TextBoxFocusReleased(textbox)
	print(textbox.Name)
end

UserInputService.TextBoxFocusReleased:Connect(TextBoxFocusReleased)

It can be used alongside UserInputService.TextBoxFocused to track when a TextBox gains and loses focus.

As this event only fires locally, it can only be used in a LocalScript.

See also:

History 3

TextBoxFocused

Parameters (1)
textboxFocusedTextBox

The TextBoxFocused event fires when a gains focus on a TextBox - typically when a client clicks/taps on a text box to begin inputting text. This also fires if a text box focus is focused using TextBox:CaptureFocus().

For example, the code below prints the name of the TextBox focused when the event fires.

1
2
3
4
5
6
7
local UserInputService = game:GetService("UserInputService")

function TextBoxFocused(textbox)
	print(textbox.Name)
end)

UserInputService.TextBoxFocused:Connect(TextBoxFocused)

It can be used alongside UserInputService.FocusReleased to track when a text box gains and loses focus.

As this event only fires locally, it can only be used in a LocalScript.

See also:

History 3

TouchDrag

Parameters (3)
dragDirectionSwipeDirection
numberOfTouchesint
gameProcessedEventbool

History 2

TouchEnabled

TypeDefault
bool

This property describes whether the user's current device has a touch screen available.

The property is used to determine if the user's device has a touch screen, and therefore if touch events will fire. If TouchEnabled is true, you can use UserInputService events such as UserInputService.TouchStarted and UserInputService.TouchEnded to track when a user starts and stops touching the screen of their device.

The code snippet below prints whether the user's device has a touch screen.

1
2
3
4
5
6
7
local UserInputService = game:GetService("UserInputService")

if UserInputService.TouchEnabled then
	print("The user's device has a touchscreen!")
else
	print("The user's device does not have a touchscreen!")
end

See also:

This property is not replicated. Its interface does not cross the network boundary.
This property is read-only. Its value can be read, but it cannot be modified.

History 6

Tags: [ReadOnly, NotReplicated]

TouchEnded

Parameters (2)
touchInputObject
gameProcessedEventbool

The TouchEnded event fires when a user released their finger from the screen of a TouchEnabled device, ending touch input with the device.

This event can be used to determine when a user stops touching the screen of their device. It can be paired with UserInputService.TouchStarted to determine when a user starts and stops touching the screen.

For example, the code below prints the screen position where the user stops touching the screen.

1
2
3
4
5
6
7
local UserInputService = game:GetService("UserInputService")

function TouchEnded(touch, gameProcessedEvent)
	print("Touch ended at " .. tostring(touch.Position))
end

UserInputService.TouchEnded:Connect(TouchEnded)

The touch input object is the same input object throughout the lifetime of the touch. So comparing InputObjects when they are touch objects is valid to determine if it is the same finger.

To check if a user's device is TouchEnabled, and that touch events will fire, see UserInputService.TouchEnabled.

This event only fires when the Roblox client window is in focus. For example, inputs will not be captured when the window is minimized.

As this event only fires locally, it can only be used in a LocalScript.

See also:

History 7

TouchLongPress

Parameters (3)
touchPositionsArray
stateUserInputState
gameProcessedEventbool

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

This event can be used to determine when a user holds their finger down on an in-game GUI or element.

The example below prints the state of the long press when the user holds at least one finger for a short amount of time on the same screen position. Possible states include: Begin, Change, End, Cancel, and None.

1
2
3
4
5
6
7
local UserInputService = game:GetService("UserInputService")

function TouchLongPress(TouchPositions, state, gameProcessedEvent)
	print("Long press event fired. State of press: " .. tostring(state))
end

UserInputService.TouchLongPress:Connect(TouchLongPress)

To check if a user's device is TouchEnabled, and that touch events will fire, seeUserInputService.TouchEnabled.

It can be paired with UserInputService.TouchStarted and UserInputService.TouchEnded to determine when a user starts and stops touching the screen.

This event only fires when the Roblox client window is in focus. For example, inputs will not be captured when the window is minimized.

As this event only fires locally, it can only be used in a LocalScript.

See also:

History 8

TouchMoved

Parameters (2)
touchInputObject
gameProcessedEventbool

The TouchMoved event fires when a user moves their finger on a TouchEnabled device.

This event can be used to determine when a user moves their finger while touching the screen of a TouchEnabled device. It can be useful to track whether a user is moving their finger on the screen, as well as where the user is moving their finger.

The code below prints "Touch moved from" the previous Vector2 position "to " the new Vector2 position of the user's touch on a TouchEnabled device.

1
2
3
4
5
6
7
8
local UserInputService = game:GetService("UserInputService")

function onTouchMoved(touch, gameProcessedEvent)
	local oldPosition = touch.Position - touch.Delta
	print("Touch moved from " .. tostring(oldPosition) .. "to " .. tostring(touch.Position))
end

UserInputService.TouchMoved:Connect(onTouchMoved)

It can be paired with UserInputService.TouchStarted and UserInputService.TouchEnded to determine when a user starts touching the screen, how their finger moves while touching it, and when the they stop touching the screen.

To check if a user's device is TouchEnabled, and that touch events will fire, see UserInputService.TouchEnabled.

This event only fires when the Roblox client window is in focus. For example, inputs will not be captured when the window is minimized.

As this event only fires locally, it can only be used in a LocalScript.

See also:

History 7

TouchPan

Parameters (5)
touchPositionsArray
totalTranslationVector2
velocityVector2
stateUserInputState
gameProcessedEventbool

The TouchPan event fires when a user drags at least one finger on a TouchEnabled device.

This event can be used to determine when a user pans their finger along screen of a TouchEnabled device - such as to rotate the Camera in a custom camera script.

The snippet below prints "Speed of touch drag" followed by the velocity of the user's touch when the user drags their finger on the screen.

1
2
3
4
5
local UserInputService = game:GetService("UserInputService")

UserInputService.TouchPan:Connect(function(touchPositions, totalTranslation, velocity, state, gameProcessedEvent)
	print("Speed of touch drag: " .. tostring(velocity))
end)

Take a look at another useful UserInputService function here UserInputService.TouchRotate.

This event only fires when the Roblox client window is in focus. For example, inputs will not be captured when the window is minimized.

As this event only fires locally, it can only be used in a LocalScript.

See also:

History 5

TouchPinch

Parameters (5)
touchPositionsArray
scalefloat
velocityfloat
stateUserInputState
gameProcessedEventbool

Fired when a user places and moves two fingers on the screen of a TouchEnabled device.

For instance, the snippet below prints how much the camera zoom scale has changed since the beginning of the touch pinch.

1
2
3
4
5
local UserInputService = game:GetService("UserInputService")

UserInputService.TouchPinch:Connect(function(touchPositions, scale, velocity, state, gameProcessedEvent)
	print("Scale difference since beginning of pinch: " .. tostring(scale))
end)

To check if a user's device is TouchEnabled, and that touch events will fire, see UserInputService.TouchEnabled.

This event only fires when the Roblox client window is in focus. For example, inputs will not be captured when the window is minimized. As this event only fires locally, it can only be used in a LocalScript.

See also:

History 7

TouchRotate

Parameters (5)
touchPositionsArray
rotationfloat
velocityfloat
stateUserInputState
gameProcessedEventbool

The TouchRotate event fires when a user rotates two fingers on a TouchEnabled device.

For example, the following code prints how much the camera has rotated since the beginning of the touch rotation.

1
2
3
4
5
local UserInputService = game:GetService("UserInputService")

UserInputService.TouchRotate:Connect(function(touchPositions, rotation, velocity, state, gameProcessedEvent)
	print("Camera has rotated " .. tostring(rotation) .. " degrees!")
end)

To check if a user's device is TouchEnabled, and that touch events will fire, see UserInputService.TouchEnabled.

This event only fires when the Roblox client window is in focus. For example, inputs will not be captured when the window is minimized.

As this event only fires locally, it can only be used in a LocalScript.

The core scripts that control the user's camera on a mobile device use code that functions similarly to this event. Best practice for this event is to use it when creating a mobile camera system to override the default core scripts.

See also:

History 7

TouchStarted

Parameters (2)
touchInputObject
gameProcessedEventbool

The TouchStarted event fires when a user places their finger on a TouchEnabled device, beginning touch input with the device.

This event can be used to determine when a user starts touching the screen of their device. It can be paired with UserInputService.TouchEnded to determine when a user starts and stops touching the screen.

The touch input object is the same input object throughout the lifetime of the touch. So comparing InputObjects when they are touch objects is valid to determine if it is the same finger.

To check if a user's device is TouchEnabled, and that touch events will fire, see UserInputService.TouchEnabled.

This event only fires when the Roblox client window is in focus. For example, inputs will not be captured when the window is minimized.

As this event only fires locally, it can only be used in a LocalScript.

See also:

History 7

TouchSwipe

Parameters (3)
swipeDirectionSwipeDirection
numberOfTouchesint
gameProcessedEventbool

The TouchSwipe event fires when a user swipes their fingers on a TouchEnabled device.

This event can be used to determine when a user swipes their fingers on the screen of their device and the direction that the user swiped.

For more precise tracking of touch input movement, use using UserInputService.TouchMoved

To check if a user's device is TouchEnabled, and that touch events will fire, see UserInputService.TouchEnabled.

This event only fires when the Roblox client window is in focus. For example, inputs will not be captured when the window is minimized.

As this event only fires locally, it can only be used in a LocalScript.

See also:

History 6

TouchTap

Parameters (2)
touchPositionsArray
gameProcessedEventbool

The TouchTap event fires when the user touches/taps their finger on the screen on a TouchEnabled device.

This event will fire regardless of whether the user touches/taps the game world or a GUI element. If you are looking for an event that only fires when the user touches/taps the game world, use UserInputService.TouchTapInWorld.

To check if a user's device is TouchEnabled, and that touch events will fire, see UserInputService.TouchEnabled.

This event only fires when the Roblox client window is in focus. For example, inputs will not be captured when the window is minimized.

As this event only fires locally, it can only be used in a LocalScript.

History 6

TouchTapInWorld

Parameters (2)
positionVector2
processedByUIbool

The TouchTapInWorld event fires when the user touches/taps their finger on the screen on a TouchEnabled device. It is fired when the user taps in the game world.

This event can be used to determine when a user taps the screen and does not tap a GUI element. If the user taps a GUI element, UserInputService.TouchTap will fire instead of TouchTapInWorld.

To check if a user's device is TouchEnabled, and that touch events will fire, see UserInputService.TouchEnabled.

This event only fires when the Roblox client window is in focus. For example, inputs will not be captured when the window is minimized.

As it only fires locally, it can only be used in a LocalScript.

See also:

History 2

UserCFrameChanged

Parameters (2)
typeUserCFrame
valueCFrame

The UserCFrameChanged event fires when the CFrame of a VR device changes.

This event can be used to track the movement of a connected VR device.

Using the event, you can implement features such as moving the user's in-game character limbs as the user moves their VR device. This can be done by changing the CFrame of the user's in-game limbs to match the CFrame changes of the VR device using the UserCFrame enum and CFrame value arguments passed by the event.

To retrieve the CFrame of a connected VR device, use UserInputService:GetUserCFrame().

As the event fires locally, it can only be used in a LocalScript.

See also:

This event is deprecated. It exists only for backward compatibility, and should not be used for new work.

History 4

Tags: [Deprecated]

UserHeadCFrame

TypeDefault
CFrame

The UserHeadCFrame used to describe the orientation and position of a user's head, if they are actively using a virtual reality headset.

This property is deprecated. It exists only for backward compatibility, and should not be used for new work.
This property is not replicated. Its interface does not cross the network boundary.
This property is read-only. Its value can be read, but it cannot be modified.

History 5

Tags: [ReadOnly, NotReplicated, Deprecated]

VREnabled

TypeDefault
bool

This property describes whether the user is using a virtual reality (VR) device.

If a VR device is enabled, you can interact with its location and movement through functions such as UserInputService:GetUserCFrame(). You can also react to VR device movement using the UserInputService.UserCFrameChanged event.

1
2
3
4
5
6
7
8
local UserInputService = game:GetService("UserInputService")

local isUsingVR = UserInputService.VREnabled
if isUsingVR then
	print("User is using a VR headset!")
else
	print("User is not using a VR headset!")
end

As UserInputService is client-side only, this property can only be used in a LocalScript.

See also:

This property is not replicated. Its interface does not cross the network boundary.
This property is read-only. Its value can be read, but it cannot be modified.

History 4

Tags: [ReadOnly, NotReplicated]

WindowFocusReleased

Parameters (0)
No parameters.

The UserInputService WindowFocusReleased event fires when the window of the Roblox client loses focus - typically when the Roblox client is minimized by the user.

For example, the code below prints "Window focus released" whenever the Roblox client loses focus.

1
2
3
4
5
local UserInputService = game:GetService("UserInputService")

UserInputService.WindowFocusReleased:Connect(function()
	print("Window focus released")
end)

This event can be used alongside UserInputService.WindowFocused to track whether the Roblox client is actively focused on a user's screen.

Since it only fires locally, it can only be used in a LocalScript.

History 4

WindowFocused

Parameters (0)
No parameters.

The UserInputService WindowFocused event fires when the window of the Roblox client gains focus - typically when the Roblox client is maximized/actively open on the user's screen.

For example, the code below prints "Window focused" whenever the Roblox client gains focus.

1
2
3
4
5
local UserInputService = game:GetService("UserInputService")

UserInputService.WindowFocused:Connect(function()
	print("Window focused")
end)

This event can be used alongside UserInputService.WindowFocusReleased to track whether the Roblox client is actively focused on a user's screen.

As this event only fires locally, it can only be used in a LocalScript.

History 4

Removed members 10

InCameraGesture

TypeDefault
bool

History 2

IsLuaTouchControls

Parameters (0)
No parameters.
Returns (1)
bool

History 2

IsStudioTouchEmulationEnabled

Parameters (0)
No parameters.
Returns (1)
bool

History 2

IsVREnabled

TypeDefault
bool
This property is deprecated. It exists only for backward compatibility, and should not be used for new work.
This property is read-only. Its value can be read, but it cannot be modified.

History 3

Tags: [ReadOnly, Deprecated]

OverrideMouseIconEnabled

TypeDefault
bool

History 2

ProcessedEvent

Parameters (2)
inputObjectInstance
processedbool

History 2

RotateCamera

Parameters (1)
positionDeltaVector2
Returns (1)
void

History 2

TouchControlsEnabled

TypeDefault
bool

History 2

ZoomCamera

Parameters (1)
zoomDeltafloat
Returns (1)
void

History 2

Settings