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.
Memory category | Instances |
---|
Member index 79
Removed member index 10
History | Member | |
---|---|---|
220 | InCameraGesture: bool | |
240 | IsVREnabled: bool | |
220 | OverrideMouseIconEnabled: bool | |
118 | TouchControlsEnabled: bool | |
230 | IsLuaTouchControls(): bool | |
230 | IsStudioTouchEmulationEnabled(): bool | |
230 | RotateCamera(positionDelta: Vector2): void | |
230 | ZoomCamera(zoomDelta: float): void | |
230 | ProcessedEvent(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
- 650 Change Security of TouchDrag from RobloxScriptSecurity to None
- 645 Change ReturnType of GetImageForKeyCode from Content to ContentId
- 645 Change ValueType of MouseIcon from Content to ContentId
- 642 Add TouchDrag
- 638 Add GetDeviceLevel
- 637 Change Tags of from [Hidden] to [Hidden, Deprecated]
- 605 Change Tags of UserCFrameChanged from [] to [Deprecated]
- 605 Change PreferredDescriptor of UserCFrameChanged from to UserCFrameChanged
- 605 Change Tags of GetUserCFrame from [] to [Deprecated]
- 605 Change PreferredDescriptor of GetUserCFrame from to GetUserCFrame
- 594 Add GetImageForKeyCode
- 573 Change ReturnType of SetNavigationGamepad from void to null
- 573 Change ReturnType of SendAppUISizes from void to null
- 573 Change ReturnType of RecenterUserHeadCFrame from void to null
- 572 Remove
- 563 Add MouseIcon
- 553 Change Default of VREnabled from to
- 553 Change Default of UserHeadCFrame from to
- 553 Change Default of TouchEnabled from to
- 553 Change Default of from to
- 553 Change Default of from to
- 553 Change Default of from to
- 553 Change Default of OnScreenKeyboardVisible from to
- 553 Change Default of OnScreenKeyboardSize from to
- 553 Change Default of OnScreenKeyboardPosition from to
- 553 Change Default of from to
- 553 Change Default of from to
- 553 Change Default of MouseIconEnabled from to
- 553 Change Default of MouseEnabled from to
- 553 Change Default of MouseDeltaSensitivity from to
- 553 Change Default of MouseBehavior from to
- 553 Change PreferredDescriptor of ModalEnabled from to TouchControlsEnabled
- 553 Change Default of ModalEnabled from to
- 553 Change Default of from to
- 553 Change Default of KeyboardEnabled from to
- 553 Change Default of GyroscopeEnabled from to
- 553 Change Default of from to
- 553 Change Default of GamepadEnabled from to
- 553 Change Default of from to
- 553 Change Default of AccelerometerEnabled from to
- 493 Change Tags of ModalEnabled from [] to [Deprecated]
- 486 Change ThreadSafety of VREnabled from ReadOnly to ReadSafe
- 486 Change ThreadSafety of UserHeadCFrame from ReadOnly to ReadSafe
- 486 Change ThreadSafety of TouchEnabled from ReadOnly to ReadSafe
- 486 Change ThreadSafety of from ReadOnly to ReadSafe
- 486 Change ThreadSafety of from ReadOnly to ReadSafe
- 486 Change ThreadSafety of from ReadOnly to ReadSafe
- 486 Change ThreadSafety of OnScreenKeyboardVisible from ReadOnly to ReadSafe
- 486 Change ThreadSafety of OnScreenKeyboardSize from ReadOnly to ReadSafe
- 486 Change ThreadSafety of OnScreenKeyboardPosition from ReadOnly to ReadSafe
- 486 Change ThreadSafety of from ReadOnly to ReadSafe
- 486 Change ThreadSafety of from ReadOnly to ReadSafe
- 486 Change ThreadSafety of MouseIconEnabled from ReadOnly to ReadSafe
- 486 Change ThreadSafety of MouseEnabled from ReadOnly to ReadSafe
- 486 Change ThreadSafety of MouseDeltaSensitivity from ReadOnly to ReadSafe
- 486 Change ThreadSafety of MouseBehavior from ReadOnly to ReadSafe
- 486 Change ThreadSafety of ModalEnabled from ReadOnly to ReadSafe
- 486 Change ThreadSafety of from ReadOnly to ReadSafe
- 486 Change ThreadSafety of KeyboardEnabled from ReadOnly to ReadSafe
- 486 Change ThreadSafety of GyroscopeEnabled from ReadOnly to ReadSafe
- 486 Change ThreadSafety of from ReadOnly to ReadSafe
- 486 Change ThreadSafety of GamepadEnabled from ReadOnly to ReadSafe
- 486 Change ThreadSafety of from ReadOnly to ReadSafe
- 486 Change ThreadSafety of AccelerometerEnabled from ReadOnly to ReadSafe
- 483 Change Parameters of TouchStarted from (touch: Instance, gameProcessedEvent: bool) to (touch: InputObject, gameProcessedEvent: bool)
- 483 Change Parameters of TouchMoved from (touch: Instance, gameProcessedEvent: bool) to (touch: InputObject, gameProcessedEvent: bool)
- 483 Change Parameters of TouchEnded from (touch: Instance, gameProcessedEvent: bool) to (touch: InputObject, gameProcessedEvent: bool)
- 483 Change Parameters of TextBoxFocused from (textboxFocused: Instance) to (textboxFocused: TextBox)
- 483 Change Parameters of TextBoxFocusReleased from (textboxReleased: Instance) to (textboxReleased: TextBox)
- 483 Change Parameters of InputEnded from (input: Instance, gameProcessedEvent: bool) to (input: InputObject, gameProcessedEvent: bool)
- 483 Change Parameters of InputChanged from (input: Instance, gameProcessedEvent: bool) to (input: InputObject, gameProcessedEvent: bool)
- 483 Change Parameters of InputBegan from (input: Instance, gameProcessedEvent: bool) to (input: InputObject, gameProcessedEvent: bool)
- 483 Change Parameters of DeviceRotationChanged from (rotation: Instance, cframe: CFrame) to (rotation: InputObject, cframe: CFrame)
- 483 Change Parameters of DeviceGravityChanged from (gravity: Instance) to (gravity: InputObject)
- 483 Change Parameters of DeviceAccelerationChanged from (acceleration: Instance) to (acceleration: InputObject)
- 483 Change ReturnType of GetFocusedTextBox from Instance to TextBox
- 483 Change ReturnType of GetDeviceGravity from Instance to InputObject
- 483 Change ReturnType of GetDeviceAcceleration from Instance to InputObject
- 469 Change Tags of from [ReadOnly, NotReplicated] to [Hidden, ReadOnly, NotReplicated]
- 469 Change Tags of from [ReadOnly, NotReplicated] to [Hidden, ReadOnly, NotReplicated]
- 469 Change Tags of from [] to [Hidden]
- 469 Change Tags of from [ReadOnly, NotReplicated] to [Hidden, ReadOnly, NotReplicated]
- 469 Change Tags of from [ReadOnly, NotReplicated] to [Hidden, ReadOnly, NotReplicated]
- 469 Change Tags of from [] to [Hidden]
- 469 Change Tags of from [ReadOnly, NotReplicated] to [Hidden, ReadOnly, NotReplicated]
- 462 Change ThreadSafety of WindowFocused from to Unsafe
- 462 Change ThreadSafety of WindowFocusReleased from to Unsafe
- 462 Change ThreadSafety of UserCFrameChanged from to Unsafe
- 462 Change ThreadSafety of TouchTapInWorld from to Unsafe
- 462 Change ThreadSafety of TouchTap from to Unsafe
- 462 Change ThreadSafety of TouchSwipe from to Unsafe
- 462 Change ThreadSafety of TouchStarted from to Unsafe
- 462 Change ThreadSafety of TouchRotate from to Unsafe
- 462 Change ThreadSafety of TouchPinch from to Unsafe
- 462 Change ThreadSafety of TouchPan from to Unsafe
- 462 Change ThreadSafety of TouchMoved from to Unsafe
- 462 Change ThreadSafety of TouchLongPress from to Unsafe
- 462 Change ThreadSafety of TouchEnded from to Unsafe
- 462 Change ThreadSafety of TextBoxFocused from to Unsafe
- 462 Change ThreadSafety of TextBoxFocusReleased from to Unsafe
- 462 Change ThreadSafety of StatusBarTapped from to Unsafe
- 462 Change ThreadSafety of PointerAction from to Unsafe
- 462 Change ThreadSafety of LastInputTypeChanged from to Unsafe
- 462 Change ThreadSafety of JumpRequest from to Unsafe
- 462 Change ThreadSafety of InputEnded from to Unsafe
- 462 Change ThreadSafety of InputChanged from to Unsafe
- 462 Change ThreadSafety of InputBegan from to Unsafe
- 462 Change ThreadSafety of GamepadDisconnected from to Unsafe
- 462 Change ThreadSafety of GamepadConnected from to Unsafe
- 462 Change ThreadSafety of DeviceRotationChanged from to Unsafe
- 462 Change ThreadSafety of DeviceGravityChanged from to Unsafe
- 462 Change ThreadSafety of DeviceAccelerationChanged from to Unsafe
- 462 Change ThreadSafety of SetNavigationGamepad from to Unsafe
- 462 Change ThreadSafety of SendAppUISizes from to Unsafe
- 462 Change ThreadSafety of RecenterUserHeadCFrame from to Unsafe
- 462 Change ThreadSafety of IsNavigationGamepad from to Unsafe
- 462 Change ThreadSafety of IsMouseButtonPressed from to Unsafe
- 462 Change ThreadSafety of IsKeyDown from to Unsafe
- 462 Change ThreadSafety of IsGamepadButtonDown from to Unsafe
- 462 Change ThreadSafety of GetUserCFrame from to Unsafe
- 462 Change ThreadSafety of GetSupportedGamepadKeyCodes from to Unsafe
- 462 Change ThreadSafety of GetStringForKeyCode from to Unsafe
- 462 Change ThreadSafety of GetPlatform from to Unsafe
- 462 Change ThreadSafety of GetNavigationGamepads from to Unsafe
- 462 Change ThreadSafety of GetMouseLocation from to Unsafe
- 462 Change ThreadSafety of GetMouseDelta from to Unsafe
- 462 Change ThreadSafety of GetMouseButtonsPressed from to Unsafe
- 462 Change ThreadSafety of GetLastInputType from to Unsafe
- 462 Change ThreadSafety of GetKeysPressed from to Unsafe
- 462 Change ThreadSafety of GetGamepadState from to Unsafe
- 462 Change ThreadSafety of GetGamepadConnected from to Unsafe
- 462 Change ThreadSafety of GetFocusedTextBox from to Unsafe
- 462 Change ThreadSafety of GetDeviceType from to Unsafe
- 462 Change ThreadSafety of GetDeviceRotation from to Unsafe
- 462 Change ThreadSafety of GetDeviceGravity from to Unsafe
- 462 Change ThreadSafety of GetDeviceAcceleration from to Unsafe
- 462 Change ThreadSafety of GetConnectedGamepads from to Unsafe
- 462 Change ThreadSafety of GamepadSupports from to Unsafe
- 462 Change ThreadSafety of VREnabled from to ReadOnly
- 462 Change ThreadSafety of UserHeadCFrame from to ReadOnly
- 462 Change ThreadSafety of TouchEnabled from to ReadOnly
- 462 Change ThreadSafety of from to ReadOnly
- 462 Change ThreadSafety of from to ReadOnly
- 462 Change ThreadSafety of from to ReadOnly
- 462 Change ThreadSafety of OnScreenKeyboardVisible from to ReadOnly
- 462 Change ThreadSafety of OnScreenKeyboardSize from to ReadOnly
- 462 Change ThreadSafety of OnScreenKeyboardPosition from to ReadOnly
- 462 Change ThreadSafety of from to ReadOnly
- 462 Change ThreadSafety of from to ReadOnly
- 462 Change ThreadSafety of MouseIconEnabled from to ReadOnly
- 462 Change ThreadSafety of MouseEnabled from to ReadOnly
- 462 Change ThreadSafety of MouseDeltaSensitivity from to ReadOnly
- 462 Change ThreadSafety of MouseBehavior from to ReadOnly
- 462 Change ThreadSafety of ModalEnabled from to ReadOnly
- 462 Change ThreadSafety of from to ReadOnly
- 462 Change ThreadSafety of KeyboardEnabled from to ReadOnly
- 462 Change ThreadSafety of GyroscopeEnabled from to ReadOnly
- 462 Change ThreadSafety of from to ReadOnly
- 462 Change ThreadSafety of GamepadEnabled from to ReadOnly
- 462 Change ThreadSafety of from to ReadOnly
- 462 Change ThreadSafety of AccelerometerEnabled from to ReadOnly
- 398 Add PointerAction
- 379 Add GetStringForKeyCode
- 377 Add GetDeviceType
- 360 Change Parameters of SendAppUISizes from (statusBarSize: Vector2, navBarSize: Vector2, bottomBarSize: Vector2) to (statusBarSize: Vector2, navBarSize: Vector2, bottomBarSize: Vector2, rightBarSize: Vector2)
- 360 Add
- 334 Add
- 330 Add IsGamepadButtonDown
- 322 Add StatusBarTapped
- 315 Add SendAppUISizes
- 314 Add
- 314 Add
- 314 Add
- 308 Add
- 297 Add TouchTapInWorld
- 297 Add IsMouseButtonPressed
- 297 Add GetMouseLocation
- 297 Add GetMouseDelta
- 297 Add GetMouseButtonsPressed
- 281 Add OnScreenKeyboardVisible
- 281 Add OnScreenKeyboardSize
- 281 Add OnScreenKeyboardPosition
- 262 Add
- 246 Add MouseDeltaSensitivity
- 240 Remove IsVREnabled
- 236 Add UserCFrameChanged
- 236 Add GetUserCFrame
- 236 Change Tags of UserHeadCFrame from [ReadOnly, NotReplicated] to [ReadOnly, NotReplicated, Deprecated]
- 234 Add RecenterUserHeadCFrame
- 230 Remove ProcessedEvent
- 230 Remove ZoomCamera
- 230 Remove RotateCamera
- 230 Remove IsStudioTouchEmulationEnabled
- 230 Remove IsLuaTouchControls
- 230 Add VREnabled
- 230 Change Tags of IsVREnabled from [ReadOnly] to [ReadOnly, Deprecated]
- 229 Add UserHeadCFrame
- 229 Add IsVREnabled
- 226 Change Security of LastInputTypeChanged from RobloxScriptSecurity to None
- 226 Change Security of GetLastInputType from RobloxScriptSecurity to None
- 220 Remove OverrideMouseIconEnabled
- 220 Remove InCameraGesture
- 217 Add GetNavigationGamepads
- 217 Add GetConnectedGamepads
- 213 Add GetFocusedTextBox
- 208 Add LastInputTypeChanged
- 208 Add GetLastInputType
- 208 Add
- 207 Add SetNavigationGamepad
- 207 Add IsNavigationGamepad
- 189 Add WindowFocused
- 189 Add WindowFocusReleased
- 189 Add IsKeyDown
- 189 Add GetKeysPressed
- 188 Remove WindowFocused
- 188 Remove WindowFocusReleased
- 188 Remove IsKeyDown
- 188 Remove GetKeysPressed
- 189 Add WindowFocused
- 189 Add WindowFocusReleased
- 189 Add IsKeyDown
- 189 Add GetKeysPressed
- 185 Add GamepadDisconnected
- 185 Add GamepadConnected
- 185 Add GetSupportedGamepadKeyCodes
- 185 Add GetGamepadState
- 185 Add GetGamepadConnected
- 185 Add GamepadSupports
- 171 Add IsStudioTouchEmulationEnabled
- 168 Add DeviceRotationChanged
- 168 Add DeviceGravityChanged
- 168 Add DeviceAccelerationChanged
- 168 Add GetDeviceRotation
- 168 Add GetDeviceGravity
- 168 Add GetDeviceAcceleration
- 168 Add OverrideMouseIconEnabled
- 168 Add GyroscopeEnabled
- 168 Add AccelerometerEnabled
- 161 Change Parameters of TouchTap from (touchPositions: Array) to (touchPositions: Array, gameProcessedEvent: bool)
- 161 Change Parameters of TouchSwipe from (swipeDirection: SwipeDirection, numberOfTouches: int) to (swipeDirection: SwipeDirection, numberOfTouches: int, gameProcessedEvent: bool)
- 161 Change Parameters of TouchStarted from (touch: Instance) to (touch: Instance, gameProcessedEvent: bool)
- 161 Change Parameters of TouchRotate from (touchPositions: Array, rotation: float, velocity: float, state: UserInputState) to (touchPositions: Array, rotation: float, velocity: float, state: UserInputState, gameProcessedEvent: bool)
- 161 Change Parameters of TouchPinch from (touchPositions: Array, scale: float, velocity: float, state: UserInputState) to (touchPositions: Array, scale: float, velocity: float, state: UserInputState, gameProcessedEvent: bool)
- 161 Change Parameters of TouchPan from (touchPositions: Array, totalTranslation: Vector2, velocity: Vector2, state: UserInputState) to (touchPositions: Array, totalTranslation: Vector2, velocity: Vector2, state: UserInputState, gameProcessedEvent: bool)
- 161 Change Parameters of TouchMoved from (touch: Instance) to (touch: Instance, gameProcessedEvent: bool)
- 161 Change Parameters of TouchLongPress from (touchPositions: Array, state: UserInputState) to (touchPositions: Array, state: UserInputState, gameProcessedEvent: bool)
- 161 Change Parameters of TouchEnded from (touch: Instance) to (touch: Instance, gameProcessedEvent: bool)
- 161 Add TextBoxFocused
- 161 Add TextBoxFocusReleased
- 161 Change Parameters of InputEnded from (input: Instance) to (input: Instance, gameProcessedEvent: bool)
- 161 Change Parameters of InputChanged from (input: Instance) to (input: Instance, gameProcessedEvent: bool)
- 161 Change Parameters of InputBegan from (input: Instance) to (input: Instance, gameProcessedEvent: bool)
- 158 Add MouseIconEnabled
- 158 Add MouseBehavior
- 156 Add GetPlatform
- 150 Add InCameraGesture
- 143 Add ProcessedEvent
- 138 Change Security of TouchTap from RobloxScriptSecurity to None
- 138 Change Security of TouchSwipe from RobloxScriptSecurity to None
- 138 Change Security of TouchStarted from RobloxScriptSecurity to None
- 138 Change Security of TouchRotate from RobloxScriptSecurity to None
- 138 Change Security of TouchPinch from RobloxScriptSecurity to None
- 138 Change Security of TouchPan from RobloxScriptSecurity to None
- 138 Change Security of TouchMoved from RobloxScriptSecurity to None
- 138 Change Security of TouchLongPress from RobloxScriptSecurity to None
- 138 Change Security of TouchEnded from RobloxScriptSecurity to None
- 138 Change Security of InputEnded from RobloxScriptSecurity to None
- 138 Change Security of InputChanged from RobloxScriptSecurity to None
- 138 Change Security of InputBegan from RobloxScriptSecurity to None
- 133 Change Parameters of TouchStarted from (touch: InputObject) to (touch: Instance)
- 133 Change Parameters of TouchMoved from (touch: InputObject) to (touch: Instance)
- 133 Change Parameters of TouchEnded from (touch: InputObject) to (touch: Instance)
- 133 Change Parameters of InputEnded from (input: InputObject) to (input: Instance)
- 133 Change Parameters of InputChanged from (input: InputObject) to (input: Instance)
- 133 Change Parameters of InputBegan from (input: InputObject) to (input: Instance)
- 131 Change Parameters of TouchTap from (position: Vector2) to (touchPositions: Array)
- 131 Change Parameters of TouchRotate from (rotation: float, velocity: float, state: UserInputState, position: Vector2) to (touchPositions: Array, rotation: float, velocity: float, state: UserInputState)
- 131 Change Parameters of TouchPinch from (scale: float, velocity: float, state: UserInputState, position: Vector2) to (touchPositions: Array, scale: float, velocity: float, state: UserInputState)
- 131 Change Parameters of TouchPan from (totalTranslation: Vector2, velocity: Vector2, numberOfTouches: int, state: UserInputState, position: Vector2) to (touchPositions: Array, totalTranslation: Vector2, velocity: Vector2, state: UserInputState)
- 131 Change Parameters of TouchLongPress from (position: UserInputState, state: Vector2) to (touchPositions: Array, state: UserInputState)
- 131 Add ZoomCamera
- 131 Add RotateCamera
- 131 Add IsLuaTouchControls
- 130 Change Parameters of TouchRotate from (rotation: float, velocity: float) to (rotation: float, velocity: float, state: UserInputState, position: Vector2)
- 130 Change Parameters of TouchPinch from (scale: float, velocity: float) to (scale: float, velocity: float, state: UserInputState, position: Vector2)
- 130 Add TouchPan
- 130 Change Parameters of TouchLongPress from (position: Vector2, state: UserInputState) to (position: UserInputState, state: Vector2)
- 128 Change Security of TouchTap from RobloxSecurity to RobloxScriptSecurity
- 128 Change Security of TouchSwipe from RobloxSecurity to RobloxScriptSecurity
- 128 Change Parameters of TouchSwipe from (swipeDirection: SwipeDirection) to (swipeDirection: SwipeDirection, numberOfTouches: int)
- 128 Change Security of TouchStarted from RobloxSecurity to RobloxScriptSecurity
- 128 Change Security of TouchRotate from RobloxSecurity to RobloxScriptSecurity
- 128 Change Security of TouchPinch from RobloxSecurity to RobloxScriptSecurity
- 128 Change Security of TouchMoved from RobloxSecurity to RobloxScriptSecurity
- 128 Change Security of TouchLongPress from RobloxSecurity to RobloxScriptSecurity
- 128 Change Parameters of TouchLongPress from (position: Vector2) to (position: Vector2, state: UserInputState)
- 128 Change Security of TouchEnded from RobloxSecurity to RobloxScriptSecurity
- 128 Add InputEnded
- 128 Add InputChanged
- 128 Add InputBegan
- 118 Change Security of JumpRequest from RobloxPlaceSecurity to None
- 118 Remove TouchControlsEnabled
- 118 Add ModalEnabled
- 115 Add TouchControlsEnabled
- 113 Add TouchTap
- 113 Add TouchSwipe
- 113 Add TouchStarted
- 113 Add TouchRotate
- 113 Add TouchPinch
- 113 Add TouchMoved
- 113 Add TouchLongPress
- 113 Add TouchEnded
- 113 Add JumpRequest
- 80 Add TouchEnabled
- 80 Add MouseEnabled
- 80 Add KeyboardEnabled
- 80 Add GamepadEnabled
- 80 Add UserInputService
- 79 Remove UserInputService
- 80 Add TouchEnabled
- 80 Add MouseEnabled
- 80 Add KeyboardEnabled
- 80 Add GamepadEnabled
- 80 Add UserInputService
Members 79
AccelerometerEnabled
Type | Default | |
---|---|---|
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 |
|
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.
Thread safety | ReadSafe |
---|---|
Category | Data |
Loaded/Saved | false/true |
History 4
- 553 Change Default of AccelerometerEnabled from to
- 486 Change ThreadSafety of AccelerometerEnabled from ReadOnly to ReadSafe
- 462 Change ThreadSafety of AccelerometerEnabled from to ReadOnly
- 168 Add AccelerometerEnabled
DeviceAccelerationChanged
Parameters (1) | |
---|---|
acceleration | InputObject |
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.
Thread safety | Unsafe |
---|
History 3
- 483 Change Parameters of DeviceAccelerationChanged from (acceleration: Instance) to (acceleration: InputObject)
- 462 Change ThreadSafety of DeviceAccelerationChanged from to Unsafe
- 168 Add DeviceAccelerationChanged
DeviceGravityChanged
Parameters (1) | |
---|---|
gravity | InputObject |
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.
Thread safety | Unsafe |
---|
History 3
- 483 Change Parameters of DeviceGravityChanged from (gravity: Instance) to (gravity: InputObject)
- 462 Change ThreadSafety of DeviceGravityChanged from to Unsafe
- 168 Add DeviceGravityChanged
DeviceRotationChanged
Parameters (2) | |
---|---|
rotation | InputObject |
cframe | CFrame |
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.
Thread safety | Unsafe |
---|
History 3
- 483 Change Parameters of DeviceRotationChanged from (rotation: Instance, cframe: CFrame) to (rotation: InputObject, cframe: CFrame)
- 462 Change ThreadSafety of DeviceRotationChanged from to Unsafe
- 168 Add DeviceRotationChanged
GamepadConnected
Parameters (1) | |
---|---|
gamepadNum | UserInputType |
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 |
|
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:
Thread safety | Unsafe |
---|
History 2
- 462 Change ThreadSafety of GamepadConnected from to Unsafe
- 185 Add GamepadConnected
GamepadDisconnected
Parameters (1) | |
---|---|
gamepadNum | UserInputType |
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 |
|
As this event fires locally, it can only be used in a LocalScript.
See also:
Thread safety | Unsafe |
---|
History 2
- 462 Change ThreadSafety of GamepadDisconnected from to Unsafe
- 185 Add GamepadDisconnected
GamepadEnabled
Type | Default | |
---|---|---|
bool |
This property describes whether the device being used by a user has an available gamepad. If gamepads are available, you can use UserInputService:GetConnectedGamepads() to retrieve a list of connected gamepads.
As UserInputService is client-side only, this property can only be used in a LocalScript.
See also:
Thread safety | ReadSafe |
---|---|
Category | Data |
Loaded/Saved | false/true |
History 6
- 553 Change Default of GamepadEnabled from to
- 486 Change ThreadSafety of GamepadEnabled from ReadOnly to ReadSafe
- 462 Change ThreadSafety of GamepadEnabled from to ReadOnly
- 80 Add GamepadEnabled
- 79 Remove UserInputService
- 80 Add GamepadEnabled
GamepadSupports
Parameters (2) | ||
---|---|---|
gamepadNum | UserInputType | |
gamepadKeyCode | KeyCode | |
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:
Thread safety | Unsafe |
---|
History 2
- 462 Change ThreadSafety of GamepadSupports from to Unsafe
- 185 Add GamepadSupports
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 |
|
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:
- UserInputService.GamepadConnected
- UserInputService.GamepadDisconnected
- UserInputService:GetConnectedGamepads()
- UserInputService:IsGamepadButtonDown()
- UserInputService:GetSupportedGamepadKeyCodes()
- UserInputService:GetGamepadState()
- UserInputService:GetGamepadConnected()
- UserInputService:GamepadSupports()
- UserInputService.GamepadEnabled
Thread safety | Unsafe |
---|
History 2
- 462 Change ThreadSafety of GetConnectedGamepads from to Unsafe
- 217 Add GetConnectedGamepads
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.
Thread safety | Unsafe |
---|
History 3
- 483 Change ReturnType of GetDeviceAcceleration from Instance to InputObject
- 462 Change ThreadSafety of GetDeviceAcceleration from to Unsafe
- 168 Add GetDeviceAcceleration
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.
Thread safety | Unsafe |
---|
History 3
- 483 Change ReturnType of GetDeviceGravity from Instance to InputObject
- 462 Change ThreadSafety of GetDeviceGravity from to Unsafe
- 168 Add GetDeviceGravity
GetDeviceLevel
Parameters (0) | ||
---|---|---|
No parameters. | ||
Returns (1) | ||
DeviceLevel |
Security | RobloxScriptSecurity |
---|---|
Thread safety | Unsafe |
History 1
- 638 Add GetDeviceLevel
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.
Thread safety | Unsafe |
---|
History 2
- 462 Change ThreadSafety of GetDeviceRotation from to Unsafe
- 168 Add GetDeviceRotation
GetDeviceType
Parameters (0) | ||
---|---|---|
No parameters. | ||
Returns (1) | ||
DeviceType |
Security | RobloxScriptSecurity |
---|---|
Thread safety | Unsafe |
History 2
- 462 Change ThreadSafety of GetDeviceType from to Unsafe
- 377 Add GetDeviceType
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:
Thread safety | Unsafe |
---|
History 3
- 483 Change ReturnType of GetFocusedTextBox from Instance to TextBox
- 462 Change ThreadSafety of GetFocusedTextBox from to Unsafe
- 213 Add GetFocusedTextBox
GetGamepadConnected
Parameters (1) | ||
---|---|---|
gamepadNum | UserInputType | |
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:
Thread safety | Unsafe |
---|
History 2
- 462 Change ThreadSafety of GetGamepadConnected from to Unsafe
- 185 Add GetGamepadConnected
GetGamepadState
Parameters (1) | ||
---|---|---|
gamepadNum | UserInputType | |
Returns (1) | ||
Array |
This function returns an array of InputObjects for all available inputs on the given UserInputType gamepad, representing each input's last input state.
To find the UserInputTypes of connected gamepads, use UserInputService:GetConnectedGamepads().
As this function only fires locally, it can only be used in a LocalScript.
See also:
Thread safety | Unsafe |
---|
History 2
- 462 Change ThreadSafety of GetGamepadState from to Unsafe
- 185 Add GetGamepadState
GetImageForKeyCode
Parameters (1) | ||
---|---|---|
keyCode | KeyCode | |
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().
Thread safety | Unsafe |
---|
History 2
- 645 Change ReturnType of GetImageForKeyCode from Content to ContentId
- 594 Add GetImageForKeyCode
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.
Thread safety | Unsafe |
---|
History 4
- 462 Change ThreadSafety of GetKeysPressed from to Unsafe
- 189 Add GetKeysPressed
- 188 Remove GetKeysPressed
- 189 Add GetKeysPressed
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.
Thread safety | Unsafe |
---|
History 3
- 462 Change ThreadSafety of GetLastInputType from to Unsafe
- 226 Change Security of GetLastInputType from RobloxScriptSecurity to None
- 208 Add GetLastInputType
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:
Name | Description |
MouseButton1 | The left mouse button. |
MouseButton2 | The right mouse button. |
MouseButton3 | The 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.
Thread safety | Unsafe |
---|
History 2
- 462 Change ThreadSafety of GetMouseButtonsPressed from to Unsafe
- 297 Add GetMouseButtonsPressed
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.
Thread safety | Unsafe |
---|
History 2
- 462 Change ThreadSafety of GetMouseDelta from to Unsafe
- 297 Add GetMouseDelta
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 GuiObject 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.
Thread safety | Unsafe |
---|
History 2
- 462 Change ThreadSafety of GetMouseLocation from to Unsafe
- 297 Add GetMouseLocation
GetPlatform
Parameters (0) | ||
---|---|---|
No parameters. | ||
Returns (1) | ||
Platform |
Security | RobloxScriptSecurity |
---|---|
Thread safety | Unsafe |
History 2
- 462 Change ThreadSafety of GetPlatform from to Unsafe
- 156 Add GetPlatform
GetStringForKeyCode
Parameters (1) | ||
---|---|---|
keyCode | KeyCode | |
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
KeyCode | Return Value |
---|---|
KeyCode.Q | Q |
KeyCode.W | W |
KeyCode.Equals | = |
KeyCode.At | 2 because @ is typed with Shift2 |
Examples on AZERTY Keyboard
KeyCode | Return Value |
---|---|
KeyCode.Q | A |
KeyCode.W | Z |
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.
KeyCode | PlayStation Return Value | Xbox Return Value |
---|---|---|
KeyCode.ButtonA | ButtonCross | ButtonA |
KeyCode.ButtonB | ButtonCircle | ButtonB |
KeyCode.ButtonX | ButtonSquare | ButtonX |
KeyCode.ButtonY | ButtonTriangle | ButtonY |
KeyCode.ButtonL1 | ButtonL1 | ButtonLB |
KeyCode.ButtonL2 | ButtonL2 | ButtonLT |
KeyCode.ButtonL3 | ButtonL3 | ButtonLS |
KeyCode.ButtonR1 | ButtonR1 | ButtonRB |
KeyCode.ButtonR2 | ButtonR2 | ButtonRT |
KeyCode.ButtonR3 | ButtonR3 | ButtonRS |
KeyCode.ButtonStart | ButtonOptions | ButtonStart |
KeyCode.ButtonSelect | ButtonTouchpad and ButtonShare | ButtonSelect |
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.
KeyCode | Image | Asset ID |
---|---|---|
KeyCode.ButtonX | rbxasset://textures/ui/Controls/xboxX.png | |
KeyCode.ButtonY | rbxasset://textures/ui/Controls/xboxY.png | |
KeyCode.ButtonA | rbxasset://textures/ui/Controls/xboxA.png | |
KeyCode.ButtonB | rbxasset://textures/ui/Controls/xboxB.png | |
KeyCode.DPadLeft | rbxasset://textures/ui/Controls/dpadLeft.png | |
KeyCode.DPadRight | rbxasset://textures/ui/Controls/dpadRight.png | |
KeyCode.DPadUp | rbxasset://textures/ui/Controls/dpadUp.png | |
KeyCode.DPadDown | rbxasset://textures/ui/Controls/dpadDown.png | |
KeyCode.ButtonSelect | rbxasset://textures/ui/Controls/xboxView.png | |
KeyCode.ButtonStart | rbxasset://textures/ui/Controls/xboxmenu.png | |
KeyCode.ButtonL1 | rbxasset://textures/ui/Controls/xboxLB.png | |
KeyCode.ButtonR1 | rbxasset://textures/ui/Controls/xboxRB.png | |
KeyCode.ButtonL2 | rbxasset://textures/ui/Controls/xboxLT.png | |
KeyCode.ButtonR2 | rbxasset://textures/ui/Controls/xboxRT.png | |
KeyCode.ButtonL3 | rbxasset://textures/ui/Controls/xboxLS.png | |
KeyCode.ButtonR3 | rbxasset://textures/ui/Controls/xboxRS.png | |
KeyCode.Thumbstick1 | rbxasset://textures/ui/Controls/xboxLSDirectional.png | |
KeyCode.Thumbstick2 | rbxasset://textures/ui/Controls/xboxRSDirectional.png | |
KeyCode.Backspace | rbxasset://textures/ui/Controls/backspace.png | |
KeyCode.Return | rbxasset://textures/ui/Controls/return.png | |
KeyCode.LeftShift | rbxasset://textures/ui/Controls/shift.png | |
KeyCode.RightShift | rbxasset://textures/ui/Controls/shift.png | |
KeyCode.Tab | rbxasset://textures/ui/Controls/tab.png | |
KeyCode.Apostrophe | rbxasset://textures/ui/Controls/apostrophe.png | |
KeyCode.Comma | rbxasset://textures/ui/Controls/comma.png | |
KeyCode.Backquote | rbxasset://textures/ui/Controls/graveaccent.png | |
KeyCode.Period | rbxasset://textures/ui/Controls/period.png | |
KeyCode.Space | rbxasset://textures/ui/Controls/spacebar.png |
Thread safety | Unsafe |
---|
History 2
- 462 Change ThreadSafety of GetStringForKeyCode from to Unsafe
- 379 Add GetStringForKeyCode
GetSupportedGamepadKeyCodes
Parameters (1) | ||
---|---|---|
gamepadNum | UserInputType | |
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:
Thread safety | Unsafe |
---|
History 2
- 462 Change ThreadSafety of GetSupportedGamepadKeyCodes from to Unsafe
- 185 Add GetSupportedGamepadKeyCodes
GetUserCFrame
Parameters (1) | ||
---|---|---|
type | UserCFrame | |
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 |
|
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:
- UserInputService.UserCFrameChanged, an event which fires when the CFrame of a VR device changes
- VRService, a service used to implement VR support
As this event only fires locally, it can only be used in a LocalScript.
Thread safety | Unsafe |
---|
History 4
- 605 Change Tags of GetUserCFrame from [] to [Deprecated]
- 605 Change PreferredDescriptor of GetUserCFrame from to GetUserCFrame
- 462 Change ThreadSafety of GetUserCFrame from to Unsafe
- 236 Add GetUserCFrame
GyroscopeEnabled
Type | Default | |
---|---|---|
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 |
|
As UserInputService is client-side only, this property can only be used in a LocalScript.
Thread safety | ReadSafe |
---|---|
Category | Data |
Loaded/Saved | false/true |
History 4
- 553 Change Default of GyroscopeEnabled from to
- 486 Change ThreadSafety of GyroscopeEnabled from ReadOnly to ReadSafe
- 462 Change ThreadSafety of GyroscopeEnabled from to ReadOnly
- 168 Add GyroscopeEnabled
InputBegan
Parameters (2) | |
---|---|
input | InputObject |
gameProcessedEvent | bool |
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.
Thread safety | Unsafe |
---|
History 6
- 483 Change Parameters of InputBegan from (input: Instance, gameProcessedEvent: bool) to (input: InputObject, gameProcessedEvent: bool)
- 462 Change ThreadSafety of InputBegan from to Unsafe
- 161 Change Parameters of InputBegan from (input: Instance) to (input: Instance, gameProcessedEvent: bool)
- 138 Change Security of InputBegan from RobloxScriptSecurity to None
- 133 Change Parameters of InputBegan from (input: InputObject) to (input: Instance)
- 128 Add InputBegan
InputChanged
Parameters (2) | |
---|---|
input | InputObject |
gameProcessedEvent | bool |
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.
Thread safety | Unsafe |
---|
History 6
- 483 Change Parameters of InputChanged from (input: Instance, gameProcessedEvent: bool) to (input: InputObject, gameProcessedEvent: bool)
- 462 Change ThreadSafety of InputChanged from to Unsafe
- 161 Change Parameters of InputChanged from (input: Instance) to (input: Instance, gameProcessedEvent: bool)
- 138 Change Security of InputChanged from RobloxScriptSecurity to None
- 133 Change Parameters of InputChanged from (input: InputObject) to (input: Instance)
- 128 Add InputChanged
InputEnded
Parameters (2) | |
---|---|
input | InputObject |
gameProcessedEvent | bool |
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.
Thread safety | Unsafe |
---|
History 6
- 483 Change Parameters of InputEnded from (input: Instance, gameProcessedEvent: bool) to (input: InputObject, gameProcessedEvent: bool)
- 462 Change ThreadSafety of InputEnded from to Unsafe
- 161 Change Parameters of InputEnded from (input: Instance) to (input: Instance, gameProcessedEvent: bool)
- 138 Change Security of InputEnded from RobloxScriptSecurity to None
- 133 Change Parameters of InputEnded from (input: InputObject) to (input: Instance)
- 128 Add InputEnded
IsGamepadButtonDown
Parameters (2) | ||
---|---|---|
gamepadNum | UserInputType | |
gamepadKeyCode | KeyCode | |
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 |
|
Since UserInputService is client-side only, this function can only be used in a LocalScript.
See also:
- UserInputService.GamepadConnected
- UserInputService.GamepadDisconnected
- UserInputService:GetConnectedGamepads()
- UserInputService:GetSupportedGamepadKeyCodes()
- UserInputService:GetGamepadState()
- UserInputService:GetGamepadConnected()
- UserInputService:GamepadSupports()
- UserInputService.GamepadEnabled
- UserInputService:IsKeyDown() - A similar method with a different use: To check if a given key on a keyboard is pressed.
Thread safety | Unsafe |
---|
History 2
- 462 Change ThreadSafety of IsGamepadButtonDown from to Unsafe
- 330 Add IsGamepadButtonDown
IsKeyDown
Parameters (1) | ||
---|---|---|
keyCode | KeyCode | |
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 |
|
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:
- UserInputType.IsGamepadButtonDown - A similar event with a different use: To check if a given button on a gamepad is pressed.
Thread safety | Unsafe |
---|
IsMouseButtonPressed
Parameters (1) | ||
---|---|---|
mouseButton | UserInputType | |
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 |
|
Since UserInputService is client-side only, this function can only be used in a LocalScript."
Thread safety | Unsafe |
---|
History 2
- 462 Change ThreadSafety of IsMouseButtonPressed from to Unsafe
- 297 Add IsMouseButtonPressed
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 |
|
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.
Thread safety | Unsafe |
---|
History 3
- 462 Change ThreadSafety of JumpRequest from to Unsafe
- 118 Change Security of JumpRequest from RobloxPlaceSecurity to None
- 113 Add JumpRequest
KeyboardEnabled
Type | Default | |
---|---|---|
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.
Thread safety | ReadSafe |
---|---|
Category | Data |
Loaded/Saved | false/true |
History 6
- 553 Change Default of KeyboardEnabled from to
- 486 Change ThreadSafety of KeyboardEnabled from ReadOnly to ReadSafe
- 462 Change ThreadSafety of KeyboardEnabled from to ReadOnly
- 80 Add KeyboardEnabled
- 79 Remove UserInputService
- 80 Add KeyboardEnabled
LastInputTypeChanged
Parameters (1) | |
---|---|
lastInputType | UserInputType |
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.
Thread safety | Unsafe |
---|
History 3
- 462 Change ThreadSafety of LastInputTypeChanged from to Unsafe
- 226 Change Security of LastInputTypeChanged from RobloxScriptSecurity to None
- 208 Add LastInputTypeChanged
ModalEnabled
Type | Default | |
---|---|---|
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.
Thread safety | ReadSafe |
---|---|
Category | Behavior |
Loaded/Saved | false |
History 6
- 553 Change PreferredDescriptor of ModalEnabled from to TouchControlsEnabled
- 553 Change Default of ModalEnabled from to
- 493 Change Tags of ModalEnabled from [] to [Deprecated]
- 486 Change ThreadSafety of ModalEnabled from ReadOnly to ReadSafe
- 462 Change ThreadSafety of ModalEnabled from to ReadOnly
- 118 Add ModalEnabled
MouseBehavior
Type | Default | |
---|---|---|
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:
- Default: The mouse moves freely around the user's screen.
- LockCenter: The mouse is locked, and cannot move from, the center of the user's screen.
- 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.
Thread safety | ReadSafe |
---|---|
Category | Data |
Loaded/Saved | true |
History 4
- 553 Change Default of MouseBehavior from to
- 486 Change ThreadSafety of MouseBehavior from ReadOnly to ReadSafe
- 462 Change ThreadSafety of MouseBehavior from to ReadOnly
- 158 Add MouseBehavior
MouseDeltaSensitivity
Type | Default | |
---|---|---|
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).
Thread safety | ReadSafe |
---|---|
Category | Data |
Loaded/Saved | true/false |
History 4
- 553 Change Default of MouseDeltaSensitivity from to
- 486 Change ThreadSafety of MouseDeltaSensitivity from ReadOnly to ReadSafe
- 462 Change ThreadSafety of MouseDeltaSensitivity from to ReadOnly
- 246 Add MouseDeltaSensitivity
MouseEnabled
Type | Default | |
---|---|---|
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 |
|
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:
Thread safety | ReadSafe |
---|---|
Category | Data |
Loaded/Saved | false/true |
History 6
- 553 Change Default of MouseEnabled from to
- 486 Change ThreadSafety of MouseEnabled from ReadOnly to ReadSafe
- 462 Change ThreadSafety of MouseEnabled from to ReadOnly
- 80 Add MouseEnabled
- 79 Remove UserInputService
- 80 Add MouseEnabled
MouseIcon
Type | Default | |
---|---|---|
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.
Thread safety | ReadSafe |
---|---|
Category | Data |
Loaded/Saved | true |
MouseIconEnabled
Type | Default | |
---|---|---|
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 |
|
As UserInputService is client-side only, this property can only be used in a LocalScript.
Thread safety | ReadSafe |
---|---|
Category | Data |
Loaded/Saved | true |
History 4
- 553 Change Default of MouseIconEnabled from to
- 486 Change ThreadSafety of MouseIconEnabled from ReadOnly to ReadSafe
- 462 Change ThreadSafety of MouseIconEnabled from to ReadOnly
- 158 Add MouseIconEnabled
OnScreenKeyboardPosition
Type | Default | |
---|---|---|
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.
Thread safety | ReadSafe |
---|---|
Category | Data |
Loaded/Saved | false |
History 4
- 553 Change Default of OnScreenKeyboardPosition from to
- 486 Change ThreadSafety of OnScreenKeyboardPosition from ReadOnly to ReadSafe
- 462 Change ThreadSafety of OnScreenKeyboardPosition from to ReadOnly
- 281 Add OnScreenKeyboardPosition
OnScreenKeyboardSize
Type | Default | |
---|---|---|
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.
Thread safety | ReadSafe |
---|---|
Category | Data |
Loaded/Saved | false |
History 4
- 553 Change Default of OnScreenKeyboardSize from to
- 486 Change ThreadSafety of OnScreenKeyboardSize from ReadOnly to ReadSafe
- 462 Change ThreadSafety of OnScreenKeyboardSize from to ReadOnly
- 281 Add OnScreenKeyboardSize
OnScreenKeyboardVisible
Type | Default | |
---|---|---|
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.
Thread safety | ReadSafe |
---|---|
Category | Data |
Loaded/Saved | false |
History 4
- 553 Change Default of OnScreenKeyboardVisible from to
- 486 Change ThreadSafety of OnScreenKeyboardVisible from ReadOnly to ReadSafe
- 462 Change ThreadSafety of OnScreenKeyboardVisible from to ReadOnly
- 281 Add OnScreenKeyboardVisible
PointerAction
Parameters (4) | |
---|---|
wheel | float |
pan | Vector2 |
pinch | float |
gameProcessedEvent | bool |
PointerAction fires when the user performs a specific pointer action. In particular, scrolling the mouse wheel.
Thread safety | Unsafe |
---|
History 2
- 462 Change ThreadSafety of PointerAction from to Unsafe
- 398 Add PointerAction
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.
Thread safety | Unsafe |
---|
History 3
- 573 Change ReturnType of RecenterUserHeadCFrame from void to null
- 462 Change ThreadSafety of RecenterUserHeadCFrame from to Unsafe
- 234 Add RecenterUserHeadCFrame
SendAppUISizes
Parameters (4) | ||
---|---|---|
statusBarSize | Vector2 | |
navBarSize | Vector2 | |
bottomBarSize | Vector2 | |
rightBarSize | Vector2 | |
Returns (1) | ||
null |
Security | RobloxScriptSecurity |
---|---|
Thread safety | Unsafe |
History 4
- 573 Change ReturnType of SendAppUISizes from void to null
- 462 Change ThreadSafety of SendAppUISizes from to Unsafe
- 360 Change Parameters of SendAppUISizes from (statusBarSize: Vector2, navBarSize: Vector2, bottomBarSize: Vector2) to (statusBarSize: Vector2, navBarSize: Vector2, bottomBarSize: Vector2, rightBarSize: Vector2)
- 315 Add SendAppUISizes
StatusBarTapped
Parameters (1) | |
---|---|
position | Vector2 |
Security | RobloxScriptSecurity |
---|---|
Thread safety | Unsafe |
History 2
- 462 Change ThreadSafety of StatusBarTapped from to Unsafe
- 322 Add StatusBarTapped
TextBoxFocusReleased
Parameters (1) | |
---|---|
textboxReleased | TextBox |
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 |
|
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:
Thread safety | Unsafe |
---|
History 3
- 483 Change Parameters of TextBoxFocusReleased from (textboxReleased: Instance) to (textboxReleased: TextBox)
- 462 Change ThreadSafety of TextBoxFocusReleased from to Unsafe
- 161 Add TextBoxFocusReleased
TextBoxFocused
Parameters (1) | |
---|---|
textboxFocused | TextBox |
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 |
|
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:
Thread safety | Unsafe |
---|
History 3
- 483 Change Parameters of TextBoxFocused from (textboxFocused: Instance) to (textboxFocused: TextBox)
- 462 Change ThreadSafety of TextBoxFocused from to Unsafe
- 161 Add TextBoxFocused
TouchDrag
Parameters (3) | |
---|---|
dragDirection | SwipeDirection |
numberOfTouches | int |
gameProcessedEvent | bool |
Thread safety | Unsafe |
---|
TouchEnabled
Type | Default | |
---|---|---|
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 |
|
See also:
Thread safety | ReadSafe |
---|---|
Category | Data |
Loaded/Saved | false/true |
History 6
- 553 Change Default of TouchEnabled from to
- 486 Change ThreadSafety of TouchEnabled from ReadOnly to ReadSafe
- 462 Change ThreadSafety of TouchEnabled from to ReadOnly
- 80 Add TouchEnabled
- 79 Remove UserInputService
- 80 Add TouchEnabled
TouchEnded
Parameters (2) | |
---|---|
touch | InputObject |
gameProcessedEvent | bool |
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 |
|
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:
Thread safety | Unsafe |
---|
History 7
- 483 Change Parameters of TouchEnded from (touch: Instance, gameProcessedEvent: bool) to (touch: InputObject, gameProcessedEvent: bool)
- 462 Change ThreadSafety of TouchEnded from to Unsafe
- 161 Change Parameters of TouchEnded from (touch: Instance) to (touch: Instance, gameProcessedEvent: bool)
- 138 Change Security of TouchEnded from RobloxScriptSecurity to None
- 133 Change Parameters of TouchEnded from (touch: InputObject) to (touch: Instance)
- 128 Change Security of TouchEnded from RobloxSecurity to RobloxScriptSecurity
- 113 Add TouchEnded
TouchLongPress
Parameters (3) | |
---|---|
touchPositions | Array |
state | UserInputState |
gameProcessedEvent | bool |
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 GuiObject 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 |
|
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:
Thread safety | Unsafe |
---|
History 8
- 462 Change ThreadSafety of TouchLongPress from to Unsafe
- 161 Change Parameters of TouchLongPress from (touchPositions: Array, state: UserInputState) to (touchPositions: Array, state: UserInputState, gameProcessedEvent: bool)
- 138 Change Security of TouchLongPress from RobloxScriptSecurity to None
- 131 Change Parameters of TouchLongPress from (position: UserInputState, state: Vector2) to (touchPositions: Array, state: UserInputState)
- 130 Change Parameters of TouchLongPress from (position: Vector2, state: UserInputState) to (position: UserInputState, state: Vector2)
- 128 Change Security of TouchLongPress from RobloxSecurity to RobloxScriptSecurity
- 128 Change Parameters of TouchLongPress from (position: Vector2) to (position: Vector2, state: UserInputState)
- 113 Add TouchLongPress
TouchMoved
Parameters (2) | |
---|---|
touch | InputObject |
gameProcessedEvent | bool |
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 |
|
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:
Thread safety | Unsafe |
---|
History 7
- 483 Change Parameters of TouchMoved from (touch: Instance, gameProcessedEvent: bool) to (touch: InputObject, gameProcessedEvent: bool)
- 462 Change ThreadSafety of TouchMoved from to Unsafe
- 161 Change Parameters of TouchMoved from (touch: Instance) to (touch: Instance, gameProcessedEvent: bool)
- 138 Change Security of TouchMoved from RobloxScriptSecurity to None
- 133 Change Parameters of TouchMoved from (touch: InputObject) to (touch: Instance)
- 128 Change Security of TouchMoved from RobloxSecurity to RobloxScriptSecurity
- 113 Add TouchMoved
TouchPan
Parameters (5) | |
---|---|
touchPositions | Array |
totalTranslation | Vector2 |
velocity | Vector2 |
state | UserInputState |
gameProcessedEvent | bool |
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 |
|
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:
Thread safety | Unsafe |
---|
History 5
- 462 Change ThreadSafety of TouchPan from to Unsafe
- 161 Change Parameters of TouchPan from (touchPositions: Array, totalTranslation: Vector2, velocity: Vector2, state: UserInputState) to (touchPositions: Array, totalTranslation: Vector2, velocity: Vector2, state: UserInputState, gameProcessedEvent: bool)
- 138 Change Security of TouchPan from RobloxScriptSecurity to None
- 131 Change Parameters of TouchPan from (totalTranslation: Vector2, velocity: Vector2, numberOfTouches: int, state: UserInputState, position: Vector2) to (touchPositions: Array, totalTranslation: Vector2, velocity: Vector2, state: UserInputState)
- 130 Add TouchPan
TouchPinch
Parameters (5) | |
---|---|
touchPositions | Array |
scale | float |
velocity | float |
state | UserInputState |
gameProcessedEvent | bool |
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 |
|
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:
Thread safety | Unsafe |
---|
History 7
- 462 Change ThreadSafety of TouchPinch from to Unsafe
- 161 Change Parameters of TouchPinch from (touchPositions: Array, scale: float, velocity: float, state: UserInputState) to (touchPositions: Array, scale: float, velocity: float, state: UserInputState, gameProcessedEvent: bool)
- 138 Change Security of TouchPinch from RobloxScriptSecurity to None
- 131 Change Parameters of TouchPinch from (scale: float, velocity: float, state: UserInputState, position: Vector2) to (touchPositions: Array, scale: float, velocity: float, state: UserInputState)
- 130 Change Parameters of TouchPinch from (scale: float, velocity: float) to (scale: float, velocity: float, state: UserInputState, position: Vector2)
- 128 Change Security of TouchPinch from RobloxSecurity to RobloxScriptSecurity
- 113 Add TouchPinch
TouchRotate
Parameters (5) | |
---|---|
touchPositions | Array |
rotation | float |
velocity | float |
state | UserInputState |
gameProcessedEvent | bool |
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 |
|
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:
Thread safety | Unsafe |
---|
History 7
- 462 Change ThreadSafety of TouchRotate from to Unsafe
- 161 Change Parameters of TouchRotate from (touchPositions: Array, rotation: float, velocity: float, state: UserInputState) to (touchPositions: Array, rotation: float, velocity: float, state: UserInputState, gameProcessedEvent: bool)
- 138 Change Security of TouchRotate from RobloxScriptSecurity to None
- 131 Change Parameters of TouchRotate from (rotation: float, velocity: float, state: UserInputState, position: Vector2) to (touchPositions: Array, rotation: float, velocity: float, state: UserInputState)
- 130 Change Parameters of TouchRotate from (rotation: float, velocity: float) to (rotation: float, velocity: float, state: UserInputState, position: Vector2)
- 128 Change Security of TouchRotate from RobloxSecurity to RobloxScriptSecurity
- 113 Add TouchRotate
TouchStarted
Parameters (2) | |
---|---|
touch | InputObject |
gameProcessedEvent | bool |
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:
Thread safety | Unsafe |
---|
History 7
- 483 Change Parameters of TouchStarted from (touch: Instance, gameProcessedEvent: bool) to (touch: InputObject, gameProcessedEvent: bool)
- 462 Change ThreadSafety of TouchStarted from to Unsafe
- 161 Change Parameters of TouchStarted from (touch: Instance) to (touch: Instance, gameProcessedEvent: bool)
- 138 Change Security of TouchStarted from RobloxScriptSecurity to None
- 133 Change Parameters of TouchStarted from (touch: InputObject) to (touch: Instance)
- 128 Change Security of TouchStarted from RobloxSecurity to RobloxScriptSecurity
- 113 Add TouchStarted
TouchSwipe
Parameters (3) | |
---|---|
swipeDirection | SwipeDirection |
numberOfTouches | int |
gameProcessedEvent | bool |
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:
Thread safety | Unsafe |
---|
History 6
- 462 Change ThreadSafety of TouchSwipe from to Unsafe
- 161 Change Parameters of TouchSwipe from (swipeDirection: SwipeDirection, numberOfTouches: int) to (swipeDirection: SwipeDirection, numberOfTouches: int, gameProcessedEvent: bool)
- 138 Change Security of TouchSwipe from RobloxScriptSecurity to None
- 128 Change Security of TouchSwipe from RobloxSecurity to RobloxScriptSecurity
- 128 Change Parameters of TouchSwipe from (swipeDirection: SwipeDirection) to (swipeDirection: SwipeDirection, numberOfTouches: int)
- 113 Add TouchSwipe
TouchTap
Parameters (2) | |
---|---|
touchPositions | Array |
gameProcessedEvent | bool |
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 GuiObject 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.
Thread safety | Unsafe |
---|
History 6
- 462 Change ThreadSafety of TouchTap from to Unsafe
- 161 Change Parameters of TouchTap from (touchPositions: Array) to (touchPositions: Array, gameProcessedEvent: bool)
- 138 Change Security of TouchTap from RobloxScriptSecurity to None
- 131 Change Parameters of TouchTap from (position: Vector2) to (touchPositions: Array)
- 128 Change Security of TouchTap from RobloxSecurity to RobloxScriptSecurity
- 113 Add TouchTap
TouchTapInWorld
Parameters (2) | |
---|---|
position | Vector2 |
processedByUI | bool |
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 GuiObject 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:
Thread safety | Unsafe |
---|
History 2
- 462 Change ThreadSafety of TouchTapInWorld from to Unsafe
- 297 Add TouchTapInWorld
UserCFrameChanged
Parameters (2) | |
---|---|
type | UserCFrame |
value | CFrame |
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:
- VRService, used to implement support, including an identical event VRService.UserHeadCFrameChanged
- Camera.HeadLocked, when this property is
true
the Camera will automatically track the head motion of a player using a VR device - Camera:GetRenderCFrame(), a function which retrieves the CFrame the Camera is being orientated at, including the impact of VR devices
Thread safety | Unsafe |
---|
History 4
- 605 Change Tags of UserCFrameChanged from [] to [Deprecated]
- 605 Change PreferredDescriptor of UserCFrameChanged from to UserCFrameChanged
- 462 Change ThreadSafety of UserCFrameChanged from to Unsafe
- 236 Add UserCFrameChanged
UserHeadCFrame
Type | Default | |
---|---|---|
CFrame |
The UserHeadCFrame used to describe the orientation and position of a user's head, if they are actively using a virtual reality headset.
Thread safety | ReadSafe |
---|---|
Category | Data |
Loaded/Saved | false |
History 5
- 553 Change Default of UserHeadCFrame from to
- 486 Change ThreadSafety of UserHeadCFrame from ReadOnly to ReadSafe
- 462 Change ThreadSafety of UserHeadCFrame from to ReadOnly
- 236 Change Tags of UserHeadCFrame from [ReadOnly, NotReplicated] to [ReadOnly, NotReplicated, Deprecated]
- 229 Add UserHeadCFrame
VREnabled
Type | Default | |
---|---|---|
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 |
|
As UserInputService is client-side only, this property can only be used in a LocalScript.
See also:
Thread safety | ReadSafe |
---|---|
Category | Data |
Loaded/Saved | false/true |
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 |
|
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.
Thread safety | Unsafe |
---|
History 4
- 462 Change ThreadSafety of WindowFocusReleased from to Unsafe
- 189 Add WindowFocusReleased
- 188 Remove WindowFocusReleased
- 189 Add WindowFocusReleased
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 |
|
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.
Thread safety | Unsafe |
---|
History 4
- 462 Change ThreadSafety of WindowFocused from to Unsafe
- 189 Add WindowFocused
- 188 Remove WindowFocused
- 189 Add WindowFocused
Removed members 10
InCameraGesture
Type | Default | |
---|---|---|
bool |
Security | RobloxScriptSecurity |
---|---|
Category | |
Loaded/Saved | false |
History 2
- 220 Remove InCameraGesture
- 150 Add InCameraGesture
IsLuaTouchControls
Parameters (0) | ||
---|---|---|
No parameters. | ||
Returns (1) | ||
bool |
Security | RobloxScriptSecurity |
---|
History 2
- 230 Remove IsLuaTouchControls
- 131 Add IsLuaTouchControls
IsStudioTouchEmulationEnabled
Parameters (0) | ||
---|---|---|
No parameters. | ||
Returns (1) | ||
bool |
Security | RobloxScriptSecurity |
---|
History 2
IsVREnabled
Type | Default | |
---|---|---|
bool |
Category | |
---|---|
Loaded/Saved | false |
History 3
- 240 Remove IsVREnabled
- 230 Change Tags of IsVREnabled from [ReadOnly] to [ReadOnly, Deprecated]
- 229 Add IsVREnabled
OverrideMouseIconEnabled
Type | Default | |
---|---|---|
bool |
Security | RobloxScriptSecurity |
---|---|
Category | |
Loaded/Saved | false |
History 2
ProcessedEvent
Parameters (2) | |
---|---|
inputObject | Instance |
processed | bool |
Security | RobloxScriptSecurity |
---|
History 2
- 230 Remove ProcessedEvent
- 143 Add ProcessedEvent
RotateCamera
Parameters (1) | ||
---|---|---|
positionDelta | Vector2 | |
Returns (1) | ||
void |
Security | RobloxScriptSecurity |
---|
History 2
- 230 Remove RotateCamera
- 131 Add RotateCamera
TouchControlsEnabled
Type | Default | |
---|---|---|
bool |
Security | RobloxPlaceSecurity |
---|---|
Category | |
Loaded/Saved | false |
History 2
- 118 Remove TouchControlsEnabled
- 115 Add TouchControlsEnabled
ZoomCamera
Parameters (1) | ||
---|---|---|
zoomDelta | float | |
Returns (1) | ||
void |
Security | RobloxScriptSecurity |
---|
History 2
- 230 Remove ZoomCamera
- 131 Add ZoomCamera