rojo/.cursor/rules/roblox/reference/engine/classes/UserInputService.yaml
2026-02-02 12:08:47 -06:00

2463 lines
87 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# This file is automatically generated. Please don't edit it manually.
# To submit a bug report on the content, see
# https://devforum.roblox.com/c/bug-reports/documentation-issues/72
name: UserInputService
type: class
memory_category: Instances
summary: |
`UserInputService` is primarily used to detect the input types available on a
user's device, as well as detect input events.
description: |
`UserInputService` is primarily used to detect the input types available on a
user's device, as well as detect input events. It allows you to perform
different actions depending on the device and, in turn, provide the best
experience for the end user.
As this service is intended for client-side usage only, its properties,
methods, and events can only be used in a `Class.LocalScript`, a
`Class.ModuleScript` required by a `Class.LocalScript`, or a `Class.Script`
with `Class.BaseScript.RunContext|RunContext` set to `Enum.RunContext.Client`.
code_samples: []
inherits:
- Instance
descendants: []
tags:
- NotCreatable
- Service
- NotReplicated
deprecation_message: ''
properties:
- name: UserInputService.AccelerometerEnabled
summary: |
Describes whether the user's device has an accelerometer.
description: |
This property describes whether the user's device has an accelerometer, a
component found in most mobile devices that measures acceleration (change
in speed).
If the device has an enabled accelerometer, you can get its current
acceleration by using the
`Class.UserInputService:GetDeviceAcceleration()|GetDeviceAcceleration()`
method or track when the device's acceleration changes through the
`Class.UserInputService.DeviceAccelerationChanged|DeviceAccelerationChanged`
event.
code_samples:
- UserInputService-DeviceGravityChanged
type: boolean
tags:
- ReadOnly
- NotReplicated
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: false
can_save: true
capabilities:
- Input
- name: UserInputService.GamepadEnabled
summary: |
Describes whether the user's device has an available gamepad.
description: |
This property describes whether the user's device has an available
gamepad. If `true`, you can use gamepad‑related methods such as
`Class.UserInputService:GetConnectedGamepads()|GetConnectedGamepads()`.
For seamless cross-platform compatibility on mixed-input devices, see
`Class.UserInputService.PreferredInput|PreferredInput` which more
accurately reflects which input (mouse/keyboard, touch, gamepad, etc.) the
player is likely using as the **primary** input.
code_samples: []
type: boolean
tags:
- ReadOnly
- NotReplicated
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: false
can_save: true
capabilities:
- Input
- name: UserInputService.GyroscopeEnabled
summary: |
Describes whether the user's device has a gyroscope.
description: |
This property describes whether the user's device has a gyroscope, a
component found in most mobile devices that detects orientation and
rotational speed.
If the device has a gyroscope, you can incorporate it into your experience
using the `Class.UserInputService:GetDeviceRotation()|GetDeviceRotation()`
method or track when the device's rotation changes through the
`Class.UserInputService.DeviceRotationChanged|DeviceRotationChanged`
event.
code_samples: []
type: boolean
tags:
- ReadOnly
- NotReplicated
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: false
can_save: true
capabilities:
- Input
- name: UserInputService.KeyboardEnabled
summary: |
Describes whether the user's device has a keyboard available.
description: |
This property describes whether the user's device has a keyboard
available. If `true`, you can use key‑related methods such as
`Class.UserInputService:IsKeyDown()|IsKeyDown()` or
`Class.UserInputService:GetKeysPressed()|GetKeysPressed()`.
For seamless cross-platform compatibility on mixed-input devices, see
`Class.UserInputService.PreferredInput|PreferredInput` which more
accurately reflects which input (mouse/keyboard, touch, gamepad, etc.) the
player is likely using as the **primary** input.
code_samples: []
type: boolean
tags:
- ReadOnly
- NotReplicated
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: false
can_save: true
capabilities:
- Input
- name: UserInputService.ModalEnabled
summary: |
Toggles whether Roblox's mobile controls are hidden on mobile devices.
description: |
The `ModalEnabled` property determines whether character controls are
hidden on `Class.UserInputService.TouchEnabled|TouchEnabled` devices. By
default, this property is `false` and controls are visible.
This property will only work when used in a `Class.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 `Class.UserInputService.InputBegan|InputBegan` and
`Class.UserInputService.TouchSwipe|TouchSwipe` can still be used to
process other forms of input.
code_samples: []
type: boolean
tags:
- Deprecated
deprecation_message: |
This item has been superseded by `Class.GuiService.TouchControlsEnabled`
which should be used in all new work.
security:
read: None
write: None
thread_safety: ReadSafe
category: Behavior
serialization:
can_load: false
can_save: false
capabilities:
- Input
- name: UserInputService.MouseBehavior
summary: |
Determines whether the user's mouse can be moved freely or is locked.
description: |
This property sets how the user's mouse behaves based on the
`Enum.MouseBehavior` enum. It can be set to three values:
- `Enum.MouseBehavior.Default` — The mouse moves freely around the
user's screen.
- `Enum.MouseBehavior.LockCenter` — The mouse is locked and cannot
move from the center of the user's screen.
- `Enum.MouseBehavior.LockCurrentPosition` — The mouse is locked and
cannot move from its 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,
`Class.UserInputService:GetMouseDelta()|GetMouseDelta` returns the same
`Datatype.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 `Class.GuiButton` with
`Class.GuiButton.Modal|Modal` enabled is `Class.GuiButton.Visible|Visible`
unless the player's right mouse button is down.
Note that if the mouse is locked,
`Class.UserInputService.InputChanged|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
experience, the mouse will be forcefully unlocked.
code_samples: []
type: MouseBehavior
tags: []
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: true
can_save: true
capabilities:
- Input
- name: UserInputService.MouseDeltaSensitivity
summary: |
Scales the delta (change) output of the user's `Class.Mouse`.
description: |
This property determines the sensitivity of the user's `Class.Mouse`. It
can be used to adjust the sensitivity of events tracking mouse movement,
such as `Class.UserInputService:GetMouseDelta()|GetMouseDelta()`.
This property does not affect the movement of the mouse icon, nor the
camera sensitivity that the user has selected for their client.
This property has a maximum value of `10` and a minimum value of `0`. 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 `0`.
code_samples: []
type: float
tags:
- NotReplicated
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: true
can_save: false
capabilities:
- Input
- name: UserInputService.MouseEnabled
summary: |
Describes whether the user's device has a mouse available.
description: |
This property describes whether the user's device has a mouse available.
If `true`, you can use mouse‑related methods such as
`Class.UserInputService:GetMouseLocation()|GetMouseLocation()`.
For seamless cross-platform compatibility on mixed-input devices, see
`Class.UserInputService.PreferredInput|PreferredInput` which more
accurately reflects which input (mouse/keyboard, touch, gamepad, etc.) the
player is likely using as the **primary** input.
code_samples: []
type: boolean
tags:
- ReadOnly
- NotReplicated
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: false
can_save: true
capabilities:
- Input
- name: UserInputService.MouseIcon
summary: |
The content ID of the image for the user's mouse icon.
description: |
This property determines the content ID of the image for the user's mouse
icon. If blank, a default arrow pointer is used. While the cursor hovers
over certain UI objects such as an `Class.ImageButton`,
`Class.TextButton`, `Class.TextBox`, or `Class.ProximityPrompt`, this
image will be overridden and temporarily ignored.
To hide the cursor entirely, do **not** use a transparent image; instead,
set `Class.UserInputService.MouseIconEnabled|MouseIconEnabled` to `false`.
code_samples:
- UserInputService-MouseIcon
type: ContentId
tags: []
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: true
can_save: true
capabilities:
- Input
- name: UserInputService.MouseIconContent
summary: |
The content ID of the image for the user's mouse icon. Only supports asset
URIs.
description: |
This property determines the content ID of the image for the user's mouse
icon. If blank, a default arrow pointer is used. While the cursor hovers
over certain UI objects such as an `Class.ImageButton`,
`Class.TextButton`, `Class.TextBox`, or `Class.ProximityPrompt`, this
image will be overridden and temporarily ignored. Only asset URIs are
supported for this property.
To hide the cursor entirely, do **not** use a transparent image; instead,
set `Class.UserInputService.MouseIconEnabled|MouseIconEnabled` to `false`.
code_samples:
- UserInputService-MouseIcon
type: Content
tags: []
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: true
can_save: true
capabilities:
- Input
- name: UserInputService.MouseIconEnabled
summary: |
Determines whether the mouse icon is visible.
description: |
This property determines whether the mouse icon is visible. To detect when
this property changes, you must listen to when the
`Class.UserInputService.MouseEnabled|MouseEnabled` property changes.
code_samples: []
type: boolean
tags: []
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: true
can_save: true
capabilities:
- Input
- name: UserInputService.OnScreenKeyboardPosition
summary: |
Determines the position of the on-screen keyboard.
description: |
This property describes the position of the on-screen keyboard in pixels.
The keyboard's position is `Datatype.Vector2|Vector2.new(0, 0)` when it is
not visible.
See also
`Class.UserInputService.OnScreenKeyboardVisible|OnScreenKeyboardVisible`
and `Class.UserInputService.OnScreenKeyboardSize|OnScreenKeyboardSize`.
code_samples: []
type: Vector2
tags:
- ReadOnly
- NotReplicated
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: false
can_save: false
capabilities:
- Input
- name: UserInputService.OnScreenKeyboardSize
summary: |
Determines the size of the on-screen keyboard.
description: |
This property describes the size of the on-screen keyboard in pixels. The
keyboard's size is `Datatype.Vector2|Vector2.new(0, 0)` when it is not
visible.
See also
`Class.UserInputService.OnScreenKeyboardVisible|OnScreenKeyboardVisible`
and
`Class.UserInputService.OnScreenKeyboardPosition|OnScreenKeyboardPosition`.
code_samples: []
type: Vector2
tags:
- ReadOnly
- NotReplicated
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: false
can_save: false
capabilities:
- Input
- name: UserInputService.OnScreenKeyboardVisible
summary: |
Describes whether an on-screen keyboard is currently visible on the user's
screen.
description: |
This property describes whether an on-screen keyboard is currently visible
on the user's screen.
See also
`Class.UserInputService.OnScreenKeyboardSize|OnScreenKeyboardSize` and
`Class.UserInputService.OnScreenKeyboardPosition|OnScreenKeyboardPosition`.
code_samples: []
type: boolean
tags:
- ReadOnly
- NotReplicated
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: false
can_save: false
capabilities:
- Input
- name: UserInputService.PreferredInput
summary: |
Queries the primary input type a player is using, based on anticipated
user behavior.
description: |
This read-only property lets you query the **primary** input type a player
is likely using, based on anticipated user behavior, to ensure UI elements
like on‑screen buttons and menus work elegantly across devices. For
example, a touch‑enabled device assumes touch is the default input and
that touch buttons may appear for actions, but if a player connects an
additional bluetooth keyboard/mouse or gamepad, you can assume they want
to switch to that as the primary input type and possibly use touch as a
backup input for on‑screen UI.
The value of `PreferredInput` changes based on built‑in device inputs and
the player's most recent interaction with a connected gamepad or
keyboard/mouse. Examples include:
<table>
<thead>
<tr>
<th>Real-World Scenario</th>
<th><code>PreferredInput</code></th>
</tr>
</thead>
<tbody>
<tr>
<td>Player is using a phone with no other connected input devices; no possibility of an input type change.</td>
<td><code>Enum.PreferredInput|Touch</code></td>
</tr>
<tr>
<td>Player is using a mobile device with a bluetooth keyboard & mouse connected, but no gamepad is connected.</td>
<td><code>Enum.PreferredInput|KeyboardAndMouse</code></td>
</tr>
<tr>
<td>Player is using a tablet with a bluetooth gamepad connected, but no keyboard or mouse is connected.</td>
<td><code>Enum.PreferredInput|Gamepad</code></td>
</tr>
<tr>
<td>Player is using an Xbox or PlayStation with a bluetooth keyboard & mouse connected and has most recently interacted with the keyboard or mouse.</td>
<td><code>Enum.PreferredInput|KeyboardAndMouse</code></td>
</tr>
<tr>
<td>Player is on a Windows or Mac PC with a gamepad connected and has most recently interacted with the gamepad.</td>
<td><code>Enum.PreferredInput|Gamepad</code></td>
</tr>
</tbody>
</table>
code_samples:
- UserInputService-PreferredInput
type: PreferredInput
tags:
- ReadOnly
- NotReplicated
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: false
can_save: true
capabilities:
- Input
- name: UserInputService.TouchEnabled
summary: |
Describes whether the user's device has a touch screen available.
description: |
This property describes whether the user's device has a touch screen
available. If `true`, you can use touch‑related events such as
`Class.UserInputService.TouchStarted|TouchStarted` and
`Class.UserInputService.TouchMoved|TouchMoved`.
For seamless cross-platform compatibility on mixed-input devices, see
`Class.UserInputService.PreferredInput|PreferredInput` which more
accurately reflects which input (mouse/keyboard, touch, gamepad, etc.) the
player is likely using as the **primary** input.
code_samples: []
type: boolean
tags:
- ReadOnly
- NotReplicated
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: false
can_save: true
capabilities:
- Input
- name: UserInputService.TouchScreenEnabled
summary: ''
description: ''
code_samples: []
type: boolean
tags:
- ReadOnly
- NotReplicated
deprecation_message: ''
security:
read: RobloxScriptSecurity
write: RobloxScriptSecurity
thread_safety: ReadSafe
category: Data
serialization:
can_load: false
can_save: true
capabilities:
- Input
- name: UserInputService.UserHeadCFrame
summary: |
Describes the orientation and position of a user's head, if they are
actively using a virtual reality headset.
description: |
The UserHeadCFrame used to describe the orientation and position of a
user's head, if they are actively using a virtual reality headset.
code_samples: []
type: CFrame
tags:
- ReadOnly
- NotReplicated
- Deprecated
deprecation_message: |
This item has been superseded by `Class.UserInputService:GetUserCFrame()`
which should be used in all new work.
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: false
can_save: false
capabilities:
- Input
- name: UserInputService.VREnabled
summary: |
Indicates whether the user is using a virtual reality headset.
description: |
This property describes whether the user is using a virtual reality (VR)
device. If `true`, you can use VR‑related properties, methods, and events
in `Class.VRService`.
code_samples: []
type: boolean
tags:
- ReadOnly
- NotReplicated
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: false
can_save: true
capabilities:
- Input
methods:
- name: UserInputService:GamepadSupports
summary: |
Returns whether the given `Enum.UserInputType` gamepad supports a button
corresponding with the given `Enum.KeyCode`.
description: |
This method returns whether the given `Enum.UserInputType` gamepad
supports a button corresponding with the given `Enum.KeyCode`.
code_samples: []
parameters:
- name: gamepadNum
type: UserInputType
default:
summary: |
The `Enum.UserInputType` of the gamepad.
- name: gamepadKeyCode
type: KeyCode
default:
summary: |
The `Enum.KeyCode` of the button in question.
returns:
- type: boolean
summary: |
Whether the given gamepad supports a button corresponding with the
given `Enum.KeyCode`.
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
capabilities:
- Input
- name: UserInputService:GetConnectedGamepads
summary: |
Returns an array of `Enum.UserInputType` gamepads currently connected.
description: |
This method returns an array of `Enum.UserInputType` gamepads currently
connected. If no gamepads are connected, the array will be empty.
Alternatively to detecting all gamepads, the
`Class.UserInputService.PreferredInput|PreferredInput` property can be
used to more accurately reflect which input (mouse/keyboard, touch,
gamepad, etc.) the player is likely using as the **primary** input.
code_samples: []
parameters: []
returns:
- type: Array
summary: |
An array of `Enum.UserInputType|UserInputTypes` corresponding with the
gamepads connected to the user's device.
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
capabilities:
- Input
- name: UserInputService:GetDeviceAcceleration
summary: |
Returns an `Class.InputObject` that describes the device's current
acceleration.
description: |
This method returns an `Class.InputObject` that describes the device's
current acceleration. For this to function, the user's device must have an
enabled accelerometer as queried through the
`Class.UserInputService.AccelerometerEnabled|AccelerometerEnabled`
property.
To track when the device's acceleration changes, use the
`Class.UserInputService.DeviceAccelerationChanged|DeviceAccelerationChanged`
event.
code_samples:
- UserInputService-GetDeviceAcceleration
parameters: []
returns:
- type: InputObject
summary: ''
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
capabilities:
- Input
- name: UserInputService:GetDeviceGravity
summary: |
Returns an `Class.InputObject` describing the device's current gravity
vector.
description: |
This method returns an `Class.InputObject` describing the device's current
gravity vector. The vector is determined by the device's orientation
relative to the real-world force of gravity. For example:
- `Datatype.Vector3|Vector3.new(0, 0, -9.18)` if the device is perfectly
upright (portrait)
- `Datatype.Vector3|Vector3.new(9.81, 0, 0)` if the left side of the
device is pointing down
- `Datatype.Vector3|Vector3.new(0, -9.81, 0)` if the back of the device is
pointing down
Gravity is only tracked for devices with an enabled gyroscope as queried
through `Class.UserInputService.GyroscopeEnabled|GyroscopeEnabled`.
To track when the device's gravity changes, use the
`Class.UserInputService.DeviceGravityChanged|DeviceGravityChanged` event.
code_samples:
- UserInputService-GetDeviceGravity
parameters: []
returns:
- type: InputObject
summary: ''
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
capabilities:
- Input
- name: UserInputService:GetDeviceRotation
summary: |
Returns an `Class.InputObject` and a `Datatype.CFrame` describing the
device's current rotation vector.
description: |
This method returns an `Class.InputObject` and a `Datatype.CFrame`
describing the device's current rotation vector.
Device rotation is only tracked for devices with an enabled gyroscope as
queried through
`Class.UserInputService.GyroscopeEnabled|GyroscopeEnabled`.
code_samples:
- UserInputService-GetDeviceRotation
parameters: []
returns:
- type: Tuple
summary: |
A tuple containing two properties: The delta describing the amount of
rotation that last happened, and the `Datatype.CFrame` of the device's
current rotation relative to its default reference frame.
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
capabilities:
- Input
- name: UserInputService:GetFocusedTextBox
summary: |
Returns the currently `Class.TextBox` the client is currently focused on.
description: |
This method returns the `Class.TextBox` the client is currently focused
on. A `Class.TextBox` can be manually selected by the user, or selection
can be forced using the `Class.TextBox:CaptureFocus()` method. If no
`Class.TextBox` is selected, this method will return `nil`.
code_samples: []
parameters: []
returns:
- type: TextBox
summary: ''
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
capabilities:
- Input
- name: UserInputService:GetGamepadConnected
summary: |
Returns whether a gamepad with the given `Enum.UserInputType` is
connected.
description: |
This method returns whether a gamepad with the given `Enum.UserInputType`
is connected.
Alternatively to detecting a specific gamepad by `Enum.UserInputType`, the
`Class.UserInputService.PreferredInput|PreferredInput` property can be
used to more accurately reflect which input (mouse/keyboard, touch,
gamepad, etc.) the player is likely using as the **primary** input.
code_samples: []
parameters:
- name: gamepadNum
type: UserInputType
default:
summary: |
The `Enum.UserInputType` of the gamepad in question.
returns:
- type: boolean
summary: |
Whether a gamepad associated with `Enum.UserInputType` is connected.
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
capabilities:
- Input
- name: UserInputService:GetGamepadState
summary: |
Returns an array of `Class.InputObject|InputObjects` for all available
inputs on the given gamepad, representing each input's last input state.
description: |
This method returns an array of `Class.InputObject|InputObjects` for all
available inputs on the given `Enum.UserInputType` gamepad, representing
each input's last input state.
code_samples: []
parameters:
- name: gamepadNum
type: UserInputType
default:
summary: |
The `Enum.UserInputType` corresponding with the gamepad in question.
returns:
- type: Instances
summary: |
An array of `Class.InputObject|InputObjects` representing the current
state of all available inputs for the given gamepad.
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
capabilities:
- Input
- name: UserInputService:GetImageForKeyCode
summary: |
Returns an image for the requested `Enum.KeyCode`.
description: |
This method takes the requested `Enum.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&nbsp;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
`Class.UserInputService.GetStringForKeyCode()|GetStringForKeyCode()`.
code_samples:
- UserInputService-GetImageForKeyCode
parameters:
- name: keyCode
type: KeyCode
default:
summary: |
The `Enum.KeyCode` for which to fetch the associated image.
returns:
- type: ContentId
summary: |
The returned image asset ID.
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
capabilities:
- Input
- name: UserInputService:GetKeysPressed
summary: |
Returns an array of `Class.InputObject|InputObjects` associated with the
`Enum.KeyCode|keys` currently being pressed down.
description: |
This method returns an array of `Class.InputObject|InputObjects`
associated with the keys currently being pressed down. The array can be
iterated through to determine which keys are currently being pressed,
using the `Class.InputObject.KeyCode` names or values.
To check if a specific key is being pressed, use
`Class.UserInputService:IsKeyDown()|IsKeyDown()`.
code_samples: []
parameters: []
returns:
- type: Instances
summary: |
An array of `Class.InputObject|InputObjects` associated with the keys
currently being pressed.
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
capabilities:
- Input
- name: UserInputService:GetLastInputType
summary: |
Returns the `Enum.UserInputType` associated with the user's most recent
input.
description: |
This method returns the `Enum.UserInputType` associated with the user's
most recent input. For example, if the user's previous input had been
pressing the <kbd>A</kbd> key, the returned `Enum.UserInputType` value
would be `Enum.UserInputType|Keyboard`.
For seamless cross-platform compatibility on mixed-input devices, see
`Class.UserInputService.PreferredInput|PreferredInput` which more
accurately reflects which input (mouse/keyboard, touch, gamepad, etc.) the
player is likely using as the **primary** input. `GetLastInputType()`
remains for advanced workflows or control schemes that rely on detecting
and responding to the player's specific most recent `Enum.UserInputType`.
code_samples:
- UserInputService-GetLastInputType
parameters: []
returns:
- type: UserInputType
summary: |
The `Enum.UserInputType` associated with the user's most recent input.
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
capabilities:
- Input
- name: UserInputService:GetMouseButtonsPressed
summary: |
Returns an array of `Class.InputObject|InputObjects` associated with the
mouse buttons currently being held down.
description: |
This method returns an array of `Class.InputObject|InputObjects`
associated with the mouse buttons currently being held down. The array can
be iterated through to determine which buttons are currently being held,
using the `Class.InputObject.KeyCode` names or values.
Mouse buttons that are tracked by this method include `MouseButton1`
(left), `MouseButton2` (right), and `MouseButton3` (middle).
If the user is not pressing any mouse button down when the method is
called, it will return an empty array.
code_samples:
- UserInputService-GetMouseButtonsPressed
parameters: []
returns:
- type: Instances
summary: |
An array of `Class.InputObject|InputObjects` corresponding to the
mouse buttons currently being currently held down.
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
capabilities:
- Input
- name: UserInputService:GetMouseDelta
summary: |
Returns the change, in pixels, of the position of the player's
`Class.Mouse` in the last rendered frame. Only works if the mouse is
locked.
description: |
This method returns the change, in pixels, of the position of the player's
`Class.Mouse` in the last rendered frame, only if the mouse has been
locked using the `Class.UserInputService.MouseBehavior|MouseBehavior`
property; otherwise the returned `Datatype.Vector2` values will be `0`.
The sensitivity of the mouse, determined in the client's settings and
`Class.UserInputService.MouseDeltaSensitivity|MouseDeltaSensitivity`, will
influence the result.
code_samples:
- UserInputService-GetMouseDelta
parameters: []
returns:
- type: Vector2
summary: |
Change in movement of the mouse.
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
capabilities:
- Input
- name: UserInputService:GetMouseLocation
summary: |
Returns the current screen location of the player's `Class.Mouse` relative
to the top-left corner of the screen.
description: |
This method returns a `Datatype.Vector2` representing the current screen
location of the player's `Class.Mouse` in pixels relative to the top‑left
corner. This does not account for the `Enum.ScreenInsets`; to get the
top‑left and bottom‑right insets, call `Class.GuiService:GetGuiInset()`.
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.
code_samples: []
parameters: []
returns:
- type: Vector2
summary: |
A `Datatype.Vector2` representing the current screen location of the
mouse, in pixels.
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
capabilities:
- Input
- name: UserInputService:GetNavigationGamepads
summary: |
Returns an array of gamepads connected and enabled for `Class.GuiObject`
navigation in descending order of priority.
description: |
This method returns an array of gamepads that are connected and enabled
for `Class.GuiObject` navigation, but does not influence navigation
controls. This list is in descending order of priority, meaning it can be
iterated over to determine which gamepad should have navigation control.
See also
`Class.UserInputService:SetNavigationGamepad()|SetNavigationGamepad()`,
`Class.UserInputService:IsNavigationGamepad()|IsNavigationGamepad()`, and
`Class.UserInputService:GetConnectedGamepads()|GetConnectedGamepads()`.
code_samples: []
parameters: []
returns:
- type: Array
summary: |
An array of `Enum.UserInputType|UserInputTypes` that can be used for
navigation, in descending order of priority.
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
capabilities:
- Input
- name: UserInputService:GetStringForKeyCode
summary: |
Returns a string representing a key the user should press in order to
input a given `Enum.KeyCode`.
description: |
This method returns a string representing a key the user should press in
order to input a given `Enum.KeyCode`, keeping in mind their keyboard
layout. For key codes that require some modifier to be held, this method
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 <kbd>A</kbd> on an
AZERTY keyboard results in `Enum.KeyCode.Q`, potentially leading to
mismatched information on experience UI elements. This method solves the
issue by providing the actual key to be pressed while using non‑QWERTY
keyboard layouts.
<table size="small">
<thead>
<tr>
<th>KeyCode</th>
<th>QWERTY Return</th>
<th>AZERTY Return</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>Enum.KeyCode.Q</code></td>
<td><code>Q</code></td>
<td><code>A</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.W</code></td>
<td><code>W</code></td>
<td><code>Z</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.Equals</code></td>
<td><code>=</code></td>
<td><code>=</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.At</code></td>
<td><code>2</code> because <code>@</code> is typed with <kbd>Shift</kbd><kbd>2</kbd></td>
<td><code>É</code></td>
</tr>
</tbody>
</table>
#### Gamepad Usage
`GetStringForKeyCode()` returns the string mapping for the `Enum.KeyCode`
for the most recently connected gamepad. If the connected controller is
not supported, the method returns the default string conversion for the
requested key code.
The following example shows how you can map custom assets for
`Enum.KeyCode.ButtonA|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.
`Enum.KeyCode.ButtonSelect` has slightly different behavior in some cases.
Use both PlayStation mappings to ensure users see the correct buttons.
<table size="small">
<thead>
<tr>
<th>KeyCode</th>
<th>PlayStation Return Value</th>
<th>Xbox Return Value</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>Enum.KeyCode.ButtonA</code></td>
<td><code>ButtonCross</code></td>
<td><code>ButtonA</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonB</code></td>
<td><code>ButtonCircle</code></td>
<td><code>ButtonB</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonX</code></td>
<td><code>ButtonSquare</code></td>
<td><code>ButtonX</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonY</code></td>
<td><code>ButtonTriangle</code></td>
<td><code>ButtonY</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonL1</code></td>
<td><code>ButtonL1</code></td>
<td><code>ButtonLB</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonL2</code></td>
<td><code>ButtonL2</code></td>
<td><code>ButtonLT</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonL3</code></td>
<td><code>ButtonL3</code></td>
<td><code>ButtonLS</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonR1</code></td>
<td><code>ButtonR1</code></td>
<td><code>ButtonRB</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonR2</code></td>
<td><code>ButtonR2</code></td>
<td><code>ButtonRT</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonR3</code></td>
<td><code>ButtonR3</code></td>
<td><code>ButtonRS</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonStart</code></td>
<td><code>ButtonOptions</code></td>
<td><code>ButtonStart</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonSelect</code></td>
<td><code>ButtonTouchpad</code> and <code>ButtonShare</code></td>
<td><code>ButtonSelect</code></td>
</tr>
</tbody>
</table>
#### Legacy System Images
When using a `Enum.KeyCode` that may be better represented as an image,
such as for an `Class.ImageLabel` in a user interface, you can use the
following legacy icons. However, it's recommended that you use
`Class.UserInputService:GetImageForKeyCode()|GetImageForKeyCode()` as a
more modern, cross‑platform method to retrieve Xbox and PlayStation
controller icons.
<table size="small">
<thead>
<tr>
<th>KeyCode</th>
<th>Asset ID</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>Enum.KeyCode.ButtonX</code></td>
<td><code>rbxasset://textures/ui/Controls/xboxX.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonY</code></td>
<td><code>rbxasset://textures/ui/Controls/xboxY.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonA</code></td>
<td><code>rbxasset://textures/ui/Controls/xboxA.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonB</code></td>
<td><code>rbxasset://textures/ui/Controls/xboxB.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.DPadLeft</code></td>
<td><code>rbxasset://textures/ui/Controls/dpadLeft.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.DPadRight</code></td>
<td><code>rbxasset://textures/ui/Controls/dpadRight.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.DPadUp</code></td>
<td><code>rbxasset://textures/ui/Controls/dpadUp.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.DPadDown</code></td>
<td><code>rbxasset://textures/ui/Controls/dpadDown.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonSelect</code></td>
<td><code>rbxasset://textures/ui/Controls/xboxView.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonStart</code></td>
<td><code>rbxasset://textures/ui/Controls/xboxmenu.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonL1</code></td>
<td><code>rbxasset://textures/ui/Controls/xboxLB.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonR1</code></td>
<td><code>rbxasset://textures/ui/Controls/xboxRB.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonL2</code></td>
<td><code>rbxasset://textures/ui/Controls/xboxLT.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonR2</code></td>
<td><code>rbxasset://textures/ui/Controls/xboxRT.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonL3</code></td>
<td><code>rbxasset://textures/ui/Controls/xboxLS.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonR3</code></td>
<td><code>rbxasset://textures/ui/Controls/xboxRS.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.Thumbstick1</code></td>
<td><code>rbxasset://textures/ui/Controls/xboxLSDirectional.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.Thumbstick2</code></td>
<td><code>rbxasset://textures/ui/Controls/xboxRSDirectional.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.Backspace</code></td>
<td><code>rbxasset://textures/ui/Controls/backspace.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.Return</code></td>
<td><code>rbxasset://textures/ui/Controls/return.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.LeftShift</code></td>
<td><code>rbxasset://textures/ui/Controls/shift.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.RightShift</code></td>
<td><code>rbxasset://textures/ui/Controls/shift.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.Tab</code></td>
<td><code>rbxasset://textures/ui/Controls/tab.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.Quote</code></td>
<td><code>rbxasset://textures/ui/Controls/apostrophe.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.Comma</code></td>
<td><code>rbxasset://textures/ui/Controls/comma.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.Backquote</code></td>
<td><code>rbxasset://textures/ui/Controls/graveaccent.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.Period</code></td>
<td><code>rbxasset://textures/ui/Controls/period.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.Space</code></td>
<td><code>rbxasset://textures/ui/Controls/spacebar.png</code></td>
</tr>
</tbody>
</table>
code_samples: []
parameters:
- name: keyCode
type: KeyCode
default:
summary: ''
returns:
- type: string
summary: ''
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
capabilities:
- Input
- name: UserInputService:GetSupportedGamepadKeyCodes
summary: |
Returns an array of `Enum.KeyCode|KeyCodes` that the gamepad associated
with the given `Enum.UserInputType` supports.
description: |
This method returns an array of `Enum.KeyCode|KeyCodes` that the gamepad
associated with the given `Enum.UserInputType` supports. If called on a
non‑connected gamepad, returns an empty array.
To determine if a specific `Enum.KeyCode` is supported, use
`Class.UserInputService:GamepadSupports()|GamepadSupports()`.
code_samples: []
parameters:
- name: gamepadNum
type: UserInputType
default:
summary: |
The `Enum.UserInputType` of the gamepad.
returns:
- type: Array
summary: |
An array of `Enum.KeyCode|KeyCodes` supported by the given gamepad.
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
capabilities:
- Input
- name: UserInputService:GetUserCFrame
summary: |
Returns a `Datatype.CFrame` describing the position and orientation of a
specified virtual reality device.
description: |
The `Class.UserInputService:GetUserCFrame()` method returns a
`Datatype.CFrame` describing the position and orientation of a specified
`Enum.UserCFrame` virtual reality (VR) device. If the specified device is
not connected, the method returns `Datatype.CFrame|CFrame.new()`.
For example, the code snippet below prints the CFrame of the user's VR
headset.
```lua
local UserInputService = game:GetService("UserInputService")
local cframe = UserInputService:GetUserCFrame(Enum.UserCFrame.Head)
print(cframe)
```
By using the method, 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
`Enum.UserCFrame` and `Datatype.CFrame` value arguments passed by the
event.
See also:
- `Class.UserInputService.UserCFrameChanged`, an event which fires when
the `Datatype.CFrame` of a VR device changes
- `Class.VRService`, a service used to implement VR support
As this event only fires locally, it can only be used in a
`Class.LocalScript`.
code_samples:
- UserInputService-UserCFrameChanged
parameters:
- name: type
type: UserCFrame
default:
summary: |
The `Enum.UserCFrame` corresponding to the VR device.
returns:
- type: CFrame
summary: |
A `Datatype.CFrame` describing the position and orientation of the
specified VR device.
tags:
- Deprecated
deprecation_message: ''
security: None
thread_safety: Unsafe
capabilities:
- Input
- name: UserInputService:IsGamepadButtonDown
summary: |
Determines whether a particular button is pressed on a gamepad.
description: |
This method returns `true` if a particular button is pressed on a gamepad,
otherwise returns `false`.
See also `Class.InputBinding` as a way to hook gamepad and other input
interactions to `Class.InputAction|InputActions`.
code_samples: []
parameters:
- name: gamepadNum
type: UserInputType
default:
summary: |
The `Enum.UserInputType` of the given gamepad.
- name: gamepadKeyCode
type: KeyCode
default:
summary: |
The `Enum.KeyCode` of the specified gamepad button.
returns:
- type: boolean
summary: |
Whether the specified button on the given gamepad is pressed is
pressed.
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
capabilities:
- Input
- name: UserInputService:IsKeyDown
summary: |
Returns whether the given `Enum.KeyCode|key` is currently held down.
description: |
This method returns `true` if a particular key is pressed on a keyboard,
otherwise returns `false`.
See also `Class.InputBinding` as a way to hook key and other input
interactions to `Class.InputAction|InputActions`.
code_samples: []
parameters:
- name: keyCode
type: KeyCode
default:
summary: |
The `Enum.KeyCode` of the key.
returns:
- type: boolean
summary: |
Whether the specified key is being held down.
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
capabilities:
- Input
- name: UserInputService:IsMouseButtonPressed
summary: |
Returns whether the given mouse button is currently held down.
description: |
This method returns `true` if a particular mouse button is pressed,
otherwise returns `false`.
See also `Class.InputBinding` as a way to hook mouse button and other
input interactions to `Class.InputAction|InputActions`.
code_samples: []
parameters:
- name: mouseButton
type: UserInputType
default:
summary: |
The `Enum.UserInputType` of the mouse button.
returns:
- type: boolean
summary: |
Whether the given mouse button is currently held down.
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
capabilities:
- Input
- name: UserInputService:IsNavigationGamepad
summary: |
Returns `true` if the specified gamepad is allowed to control navigation
and selection `Class.GuiObject|GuiObjects`.
description: |
This method returns `true` if the specified gamepad is allowed to control
navigation and selection `Class.GuiObject|GuiObjects`.
Use `Class.UserInputService:SetNavigationGamepad()|SetNavigationGamepad()`
to set a navigation gamepad, or
`Class.UserInputService:GetNavigationGamepads()|GetNavigationGamepads()`
to get a list of all navigation gamepads.
code_samples: []
parameters:
- name: gamepadEnum
type: UserInputType
default:
summary: |
The `Enum.UserInputType` of the specified gamepad.
returns:
- type: boolean
summary: |
Whether the specified gamepad is a navigation gamepad.
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
capabilities:
- Input
- name: UserInputService:RecenterUserHeadCFrame
summary: |
Recenters the `Datatype.CFrame` of the VR headset to the current
orientation of the headset worn by the user.
description: |
This method recenters the `Datatype.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 `Datatype.CFrame.new()`.
This method behaves identically to the `Class.VRService` method
`Class.VRService:RecenterUserHeadCFrame()|RecenterUserHeadCFrame()`.
code_samples: []
parameters: []
returns:
- type: ()
summary: ''
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
capabilities:
- Input
- name: UserInputService:SetNavigationGamepad
summary: |
Sets whether or not the specified gamepad can move the `Class.GuiObject`
navigator.
description: |
This method sets whether the specified gamepad can move the
`Class.GuiObject` navigator.
Use `Class.UserInputService:IsNavigationGamepad()|IsNavigationGamepad()`
to check if a specified gamepad is a set to be a navigation gamepad, or
`Class.UserInputService:GetNavigationGamepads()|GetNavigationGamepads()`
to retrieve a list of all navigation gamepads.
code_samples: []
parameters:
- name: gamepadEnum
type: UserInputType
default:
summary: |
The `Enum.UserInputType` of the specified gamepad.
- name: enabled
type: boolean
default:
summary: |
Whether the specified gamepad can move the GUI navigator.
returns:
- type: ()
summary: ''
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
capabilities:
- Input
events:
- name: UserInputService.DeviceAccelerationChanged
summary: |
Fires when a user moves a device that has an accelerometer.
description: |
This event fires when a user moves a device that has an accelerometer, a
component found in most mobile devices that measures acceleration (change
in speed). To determine whether a user's device has an accelerometer
enabled, use
`Class.UserInputService.AccelerometerEnabled|AccelerometerEnabled`.
This event can be used along with
`Class.UserInputService:GetDeviceAcceleration()|GetDeviceAcceleration()`
to determine the current movement of a user's device.
code_samples:
- UserInputService-DeviceAccelerationChanged
parameters:
- name: acceleration
type: InputObject
default:
summary: |
An `Class.InputObject`, with a
`Class.InputObject.UserInputType|UserInputType` of
`Enum.UserInputType.Accelerometer|Accelerometer` and
`Class.InputObject.Position|Position` that shows the force of gravity
on each local device axis.
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.DeviceGravityChanged
summary: |
Fires when the force of gravity changes on a device that has an enabled
accelerometer.
description: |
This event fires when the device's gravity `Datatype.Vector3` changes on a
device that has an accelerometer. To determine whether a user's device has
an accelerometer enabled, use
`Class.UserInputService.AccelerometerEnabled|AccelerometerEnabled`.
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`.
If the device has an enabled accelerometer, you can use the
`Class.UserInputService:GetDeviceGravity()|GetDeviceGravity()` method to
get the current force of gravity on the user's device.
code_samples:
- UserInputService-DeviceGravityChanged
parameters:
- name: gravity
type: InputObject
default:
summary: |
An `Class.InputObject` with a `Class.InputObject.Position|Position`
property that shows the force of gravity on each local device axis.
This position can be used as a direction to determine the direction of
gravity relative to the device.
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.DeviceRotationChanged
summary: |
Fires when a user rotates a device that has a gyroscope.
description: |
This event fires when a user rotates a device that has a gyroscope, a
component found in most mobile devices that detects orientation and
rotational speed. To check if a user's device has an enabled gyroscope,
use `Class.UserInputService.GyroscopeEnabled|GyroscopeEnabled`.
To query the current device rotation, use the
`Class.UserInputService:GetDeviceRotation()|GetDeviceRotation()` method.
Note that this event only fires when the Roblox client window is in focus.
Inputs will not be captured when the window is minimized.
code_samples: []
parameters:
- name: rotation
type: InputObject
default:
summary: |
An `Class.InputObject` providing info about the device's rotation.
`Class.InputObject.Position|Position` represents the new rotation a
`Datatype.Vector3` positional value and
`Class.InputObject.Delta|Delta` represents the change in rotation in a
`Datatype.Vector3` positional value.
- name: cframe
type: CFrame
default:
summary: |
A `Datatype.CFrame` representing the device's current orientation.
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.GamepadConnected
summary: |
Fires when a gamepad is connected to the client.
description: |
This event fires when a gamepad is connected to the client. You can also
use `Class.UserInputService:GetConnectedGamepads()|GetConnectedGamepads()`
to find the correct gamepad to use.
Alternatively, you can detect value changes to the
`Class.UserInputService.PreferredInput|PreferredInput` property which more
accurately reflects which input (mouse/keyboard, touch, gamepad, etc.) the
player is likely using as the **primary** input.
See also `Class.UserInputService.GamepadDisconnected|GamepadDisconnected`.
code_samples: []
parameters:
- name: gamepadNum
type: UserInputType
default:
summary: |
The `Enum.UserInputType` of the connected gamepad.
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.GamepadDisconnected
summary: |
Fires when a gamepad is disconnected from the client.
description: |
This event fires when a gamepad is disconnected from the client.
Alternatively, you can detect value changes to the
`Class.UserInputService.PreferredInput|PreferredInput` property which more
accurately reflects which input (mouse/keyboard, touch, gamepad, etc.) the
player is likely using as the **primary** input.
See also `Class.UserInputService.GamepadConnected|GamepadConnected`.
code_samples: []
parameters:
- name: gamepadNum
type: UserInputType
default:
summary: |
The`Enum.UserInputType` of the disconnected gamepad.
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.InputBegan
summary: |
Fires when a user begins interacting with an input device such as a mouse
or gamepad.
description: |
This event fires when a user begins interacting with an input device such
as a mouse or gamepad, such as when they first interact with a gamepad
button, although it does not capture mouse wheel movements. Can be used
along with `Class.UserInputService.InputChanged|InputChanged` and
`Class.UserInputService.InputEnded|InputEnded` to track when user input
begins, changes, and ends.
See also `Class.InputBinding` as a way to hook input device interactions
to `Class.InputAction|InputActions`.
Note that this event only fires when the Roblox client window is in focus.
It will not fire when the window is minimized.
code_samples: []
parameters:
- name: input
type: InputObject
default:
summary: |
An `Class.InputObject` instance containing information about the
user's input.
- name: gameProcessedEvent
type: boolean
default:
summary: |
Indicates whether the engine internally observed this input and acted
on it. Generally this refers to UI processing, so if a button was
touched or clicked from this input, `gameProcessedEvent` will be
`true`.
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.InputChanged
summary: |
Fires when a user changes how they're interacting with an input device
such as a mouse or gamepad.
description: |
This event fires when a user changes how they're interacting with an input
device such as a mouse or gamepad. Can be used along with
`Class.UserInputService.InputBegan|InputBegan` and
`Class.UserInputService.InputEnded|InputEnded` to track when user input
begins, changes, and ends.
See also `Class.InputBinding` as a way to hook input device interactions
to `Class.InputAction|InputActions`.
Note that this event only fires when the Roblox client window is in focus.
It will not fire when the window is minimized.
code_samples: []
parameters:
- name: input
type: InputObject
default:
summary: |
An `Class.InputObject` instance containing information about the
user's input.
- name: gameProcessedEvent
type: boolean
default:
summary: |
Indicates whether the engine internally observed this input and acted
on it. Generally this refers to UI processing, so if a button was
touched or clicked from this input, `gameProcessedEvent` will be
`true`. To ignore events that are automatically handled by Roblox like
scrolling in a `Class.ScrollingFrame`, check that `gameProcessedEvent`
is `false`.
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.InputEnded
summary: |
Fires when a user stops interacting with an input device such as a mouse
or gamepad.
description: |
This event fires when a user stops interacting with an input device such
as a mouse or gamepad, such as when they release a gamepad button. Can be
used along with `Class.UserInputService.InputBegan|InputBegan` and
`Class.UserInputService.InputChanged|InputChanged` to track when user
input begins, changes, and ends.
See also `Class.InputBinding` as a way to hook input device interactions
to `Class.InputAction|InputActions`.
Note that this event only fires when the Roblox client window is in focus.
It will not fire when the window is minimized.
code_samples: []
parameters:
- name: input
type: InputObject
default:
summary: |
An `Class.InputObject` instance containing information about the user
input.
- name: gameProcessedEvent
type: boolean
default:
summary: |
Indicates whether the engine internally observed this input and acted
on it. Generally this refers to UI processing, so if a button was
touched or clicked from this input, `gameProcessedEvent` will be
`true`.
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.JumpRequest
summary: |
Fires whenever the client makes a request for their character to jump.
description: |
This event fires when there is a jump request from the client, for example
when the client presses the spacebar or jump button on mobile. Default
behavior is to set the player's `Class.Humanoid.Jump` property to `true`
which makes the player's character jump.
Since this event fires multiple times for a single jump request, using a
[debounce](../../../scripting/debounce.md) is recommended. This event does
not fire if `Class.Player.Character` is set to nil.
code_samples:
- UserInputService-JumpRequest
parameters: []
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.LastInputTypeChanged
summary: |
Fires whenever the client's `Enum.UserInputType` is changed.
description: |
This event fires whenever the client's `Enum.UserInputType` is changed.
To get the value of the last input type, regardless of whether it has
changed, use the
`Class.UserInputService:GetLastInputType()|GetLastInputType()` method.
code_samples: []
parameters:
- name: lastInputType
type: UserInputType
default:
summary: |
A `Enum.UserInputType` indicating the last input type.
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.PointerAction
summary: |
Fires when the user performs a specific pointer action.
description: |
This event fires when the user performs a specific pointer action
(`wheel`, `pan`, `pitch`).
code_samples: []
parameters:
- name: wheel
type: float
default:
summary: ''
- name: pan
type: Vector2
default:
summary: ''
- name: pinch
type: float
default:
summary: ''
- name: gameProcessedEvent
type: boolean
default:
summary: |
Indicates whether the engine internally observed this input and acted
on it.
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.TextBoxFocused
summary: |
Fires when the client focuses on a `Class.TextBox`.
description: |
This event fires when the client gains focus on a `Class.TextBox`,
typically when a user clicks/taps it to begin inputting text. Also fires
if the `Class.TextBox` is focused using `Class.TextBox:CaptureFocus()`.
Can be used alongside
`Class.UserInputService.TextBoxFocusReleased|TextBoxFocusReleased` to
track when a `Class.TextBox` loses focus.
See also `Class.UserInputService:GetFocusedTextBox()|GetFocusedTextBox()`,
`Class.TextBox.Focused`, and `Class.TextBox.FocusLost`.
code_samples:
- UserInputService-TextBoxFocused
parameters:
- name: textboxFocused
type: TextBox
default:
summary: |
The `Class.TextBox` that gained focus.
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.TextBoxFocusReleased
summary: |
Fires when the client loses focus on a `Class.TextBox`.
description: |
This event fires when the client loses focus on a `Class.TextBox`,
typically when a user stops text entry by pressing <kbd>Enter</kbd> or
clicking/touching elsewhere on the screen. Can be used alongside
`Class.UserInputService.TextBoxFocused|TextBoxFocused` to track when a
`Class.TextBox` gains focus.
See also `Class.UserInputService:GetFocusedTextBox()|GetFocusedTextBox()`,
`Class.TextBox.Focused`, and `Class.TextBox.FocusLost`.
code_samples:
- UserInputService-TextBoxFocused
parameters:
- name: textboxReleased
type: TextBox
default:
summary: |
The `Class.TextBox` that lost focus.
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.TouchDrag
summary: |
Fires when the user drags on the screen of a
`Class.UserInputService.TouchEnabled|TouchEnabled` device.
description: |
This event fires when the user drags on the screen of a
`Class.UserInputService.TouchEnabled|TouchEnabled` device.
Note that this event only fires when the Roblox client window is in focus.
It will not fire when the window is minimized.
code_samples: []
parameters:
- name: dragDirection
type: SwipeDirection
default:
summary: |
The predominant drag direction for the event
(`Enum.SwipeDirection|Up`, `Enum.SwipeDirection|Down`,
`Enum.SwipeDirection|Left`, or `Enum.SwipeDirection|Right`).
- name: numberOfTouches
type: int
default:
summary: |
Currently only supports one touch for a value of `1`.
- name: gameProcessedEvent
type: boolean
default:
summary: |
Indicates whether the engine internally observed this input and acted
on it. Generally this refers to UI processing, so if a button was
touched or clicked from this input, `gameProcessedEvent` will be
`true`.
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.TouchEnded
summary: |
Fires when a user releases their finger from the screen of a
`Class.UserInputService.TouchEnabled|TouchEnabled` device.
description: |
This event fires when a user releases their finger from the screen of a
`Class.UserInputService.TouchEnabled|TouchEnabled` device. Can be paired
with `Class.UserInputService.TouchStarted|TouchStarted` to determine when
a user starts and stops touching the screen.
Note that this event only fires when the Roblox client window is in focus.
It will not fire when the window is minimized.
code_samples: []
parameters:
- name: touch
type: InputObject
default:
summary: |
An `Class.InputObject` instance containing information about the
user's input. This is the same object throughout the lifetime of the
touch, so comparing `Class.InputObject|InputObjects` when they are
touch objects is valid to determine if it's the same finger.
- name: gameProcessedEvent
type: boolean
default:
summary: |
Indicates whether the engine internally observed this input and acted
on it. Generally this refers to UI processing, so if a button was
touched or clicked from this input, `gameProcessedEvent` will be
`true`.
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.TouchLongPress
summary: |
Fires when a user holds at least one finger for a short amount of time on
the screen of a `Class.UserInputService.TouchEnabled|TouchEnabled` device.
description: |
This event fires when a user holds at least one finger for a short amount
of time on the screen of a
`Class.UserInputService.TouchEnabled|TouchEnabled` device.
Note that this event only fires when the Roblox client window is in focus.
It will not fire when the window is minimized.
code_samples: []
parameters:
- name: touchPositions
type: Array
default:
summary: |
An array of `Datatype.Vector2` objects indicating the position of the
fingers involved in the gesture.
- name: state
type: UserInputState
default:
summary: |
The `Enum.UserInputState` of the gesture.
- name: gameProcessedEvent
type: boolean
default:
summary: |
Indicates whether the engine internally observed this input and acted
on it. Generally this refers to UI processing, so if a button was
touched or clicked from this input, `gameProcessedEvent` will be
`true`.
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.TouchMoved
summary: |
Fires when a user moves their finger on the screen of a
`Class.UserInputService.TouchEnabled|TouchEnabled` device.
description: |
This event fires when a user moves their finger on the screen of a
`Class.UserInputService.TouchEnabled|TouchEnabled` device, useful for
tracking whether a user is moving their finger on the screen and where
they're moving it. Can be paired with
`Class.UserInputService.TouchStarted|TouchStarted` and
`Class.UserInputService.TouchEnded|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.
Note that this event only fires when the Roblox client window is in focus.
It will not fire when the window is minimized.
code_samples: []
parameters:
- name: touch
type: InputObject
default:
summary: |
An `Class.InputObject` instance containing information about the
user's input. Note that its `Class.InputObject.Position|Position` is a
`Datatype.Vector3` but only includes **X** and **Y** coordinates
(**Z** is always `0`).
- name: gameProcessedEvent
type: boolean
default:
summary: |
Indicates whether the engine internally observed this input and acted
on it. Generally this refers to UI processing, so if a button was
touched or clicked from this input, `gameProcessedEvent` will be
`true`.
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.TouchPan
summary: |
Fires when the user drags at least one finger on the screen of a
`Class.UserInputService.TouchEnabled|TouchEnabled` device.
description: |
This event fires when the user drags at least one finger on the screen of
a `Class.UserInputService.TouchEnabled|TouchEnabled` device.
Note that this event only fires when the Roblox client window is in focus.
It will not fire when the window is minimized.
code_samples: []
parameters:
- name: touchPositions
type: Array
default:
summary: |
An array of `Datatype.Vector2|Vector2s` indicating the positions of
the touches involved in the gesture.
- name: totalTranslation
type: Vector2
default:
summary: |
The size of the pan gesture from start to end, in pixels.
- name: velocity
type: Vector2
default:
summary: |
The speed of the pan gesture in pixels per second.
- name: state
type: UserInputState
default:
summary: |
The `Enum.UserInputState` of the gesture.
- name: gameProcessedEvent
type: boolean
default:
summary: |
Indicates whether the engine internally observed this input and acted
on it. Generally this refers to UI processing, so if a button was
touched or clicked from this input, `gameProcessedEvent` will be
`true`.
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.TouchPinch
summary: |
Fires when a user performs a pinch gesture on the screen of a
`Class.UserInputService.TouchEnabled|TouchEnabled` device.
description: |
This event fires when a user performs a pinch gesture on the screen of a
`Class.UserInputService.TouchEnabled|TouchEnabled` device.
Note that this event only fires when the Roblox client window is in focus.
It will not fire when the window is minimized.
code_samples: []
parameters:
- name: touchPositions
type: Array
default:
summary: |
An array of `Datatype.Vector2|Vector2s` indicating the screen
position, in pixels, of the fingers involved in the pinch gesture.
- name: scale
type: float
default:
summary: |
The magnitude of the pinch from start to finish (in pixels) divided by
the starting pinch positions.
- name: velocity
type: float
default:
summary: |
The speed of the pinch gesture in pixels per second.
- name: state
type: UserInputState
default:
summary: |
The `Enum.UserInputState` of the gesture.
- name: gameProcessedEvent
type: boolean
default:
summary: |
Indicates whether the engine internally observed this input and acted
on it. Generally this refers to UI processing, so if a button was
touched or clicked from this input, `gameProcessedEvent` will be
`true`.
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.TouchRotate
summary: |
Fires when a user rotates two fingers on the screen of a
`Class.UserInputService.TouchEnabled|TouchEnabled` device.
description: |
This event fires when a user rotates two fingers on the screen of a
`Class.UserInputService.TouchEnabled|TouchEnabled` device.
Note that this event only fires when the Roblox client window is in focus.
It will not fire when the window is minimized.
code_samples: []
parameters:
- name: touchPositions
type: Array
default:
summary: |
An array of `Datatype.Vector2|Vector2s` indicating the positions of
the fingers involved in the gesture.
- name: rotation
type: float
default:
summary: |
The number of degree the gesture has rotated since the start of the
gesture.
- name: velocity
type: float
default:
summary: |
The change in rotation (in degrees) divided by the duration of the
change (in seconds).
- name: state
type: UserInputState
default:
summary: |
The `Enum.UserInputState` of the gesture.
- name: gameProcessedEvent
type: boolean
default:
summary: |
Indicates whether the engine internally observed this input and acted
on it. Generally this refers to UI processing, so if a button was
touched or clicked from this input, `gameProcessedEvent` will be
`true`.
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.TouchStarted
summary: |
Fires when a user places their finger on the screen of a
`Class.UserInputService.TouchEnabled|TouchEnabled` device.
description: |
This event fires when a user places their finger on the screen of a
`Class.UserInputService.TouchEnabled|TouchEnabled` device. Can be paired
with `Class.UserInputService.TouchEnded|TouchEnded` to determine when a
user starts and stops touching the screen.
Note that this event only fires when the Roblox client window is in focus.
It will not fire when the window is minimized.
code_samples: []
parameters:
- name: touch
type: InputObject
default:
summary: |
An `Class.InputObject` instance, which contains information about the
user's input. This is the same object throughout the lifetime of the
touch, so comparing `Class.InputObject|InputObjects` when they are
touch objects is valid to determine if it's the same finger.
- name: gameProcessedEvent
type: boolean
default:
summary: |
Indicates whether the engine internally observed this input and acted
on it. Generally this refers to UI processing, so if a button was
touched or clicked from this input, `gameProcessedEvent` will be
`true`.
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.TouchSwipe
summary: |
Fires on a `Class.UserInputService.TouchEnabled|TouchEnabled` device when
a user places their finger(s) down on the screen, pans across the screen,
and lifts their finger(s) off with a certain speed of movement.
description: |
This event fires on a `Class.UserInputService.TouchEnabled|TouchEnabled`
device when a user places their finger(s) down on the screen, pans across
the screen, and lifts their finger(s) off with a certain speed of
movement.
For more precise tracking of touch input movement, use
`Class.UserInputService.TouchMoved|TouchMoved`.
Note that this event only fires when the Roblox client window is in focus.
It will not fire when the window is minimized.
code_samples: []
parameters:
- name: swipeDirection
type: SwipeDirection
default:
summary: |
An `Enum.SwipeDirection` indicating the direction the user swiped.
- name: numberOfTouches
type: int
default:
summary: |
Number of touches involved in the swipe gesture.
- name: gameProcessedEvent
type: boolean
default:
summary: |
Indicates whether the engine internally observed this input and acted
on it. Generally this refers to UI processing, so if a button was
touched or clicked from this input, `gameProcessedEvent` will be
`true`.
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.TouchTap
summary: |
Fires when a user taps their finger on the screen of a
`Class.UserInputService.TouchEnabled|TouchEnabled` device.
description: |
This event fires when a user taps their finger on the screen of a
`Class.UserInputService.TouchEnabled|TouchEnabled` device, regardless of
whether the user taps in the 3D world or on a `Class.GuiObject` element.
If you're looking for an event that only fires when the user taps in the
3D world, use `Class.UserInputService.TouchTapInWorld|TouchTapInWorld`.
Note that this event only fires when the Roblox client window is in focus.
It will not fire when the window is minimized.
code_samples: []
parameters:
- name: touchPositions
type: Array
default:
summary: |
An array of `Datatype.Vector2` objects indicating the position of the
fingers involved in the tap gesture.
- name: gameProcessedEvent
type: boolean
default:
summary: |
Indicates whether the engine internally observed this input and acted
on it. Generally this refers to UI processing, so if a button was
touched or clicked from this input, `gameProcessedEvent` will be
`true`.
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.TouchTapInWorld
summary: |
Fires when a user taps their finger on the screen of a
`Class.UserInputService.TouchEnabled|TouchEnabled` device and the tap
location is in the 3D world.
description: |
This event fires when a user taps their finger on the screen of a
`Class.UserInputService.TouchEnabled|TouchEnabled` device and the tap
location is in the 3D world rather than on a `Class.GuiObject` element.
Note that this event only fires when the Roblox client window is in focus.
It will not fire when the window is minimized.
code_samples: []
parameters:
- name: position
type: Vector2
default:
summary: |
A `Datatype.Vector2` indicating the position of the tap.
- name: processedByUI
type: boolean
default:
summary: |
Whether the user tapped a UI element.
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.UserCFrameChanged
summary: |
Fires when the `Datatype.CFrame` of a specified Virtual Reality device
changes.
description: |
The UserCFrameChanged event fires when the `Datatype.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 `Enum.UserCFrame` enum and
_CFrame_ value arguments passed by the event.
To retrieve the `Datatype.CFrame` of a connected VR device, use
`Class.UserInputService:GetUserCFrame()`.
As the event fires locally, it can only be used in a `Class.LocalScript`.
See also:
- `Class.VRService`, used to implement support, including an identical
event `Class.VRService.UserHeadCFrameChanged`
- `Class.Camera.HeadLocked`, when this property is `true` the
`Class.Camera` will automatically track the head motion of a player
using a VR device
- `Class.Camera:GetRenderCFrame()`, a method which retrieves the
`Datatype.CFrame` the `Class.Camera` is being orientated at, including
the impact of VR devices
code_samples:
- UserInputService-UserCFrameChanged
parameters:
- name: type
type: UserCFrame
default:
summary: |
A `Enum.UserCFrame` value indicating which body part moved.
- name: value
type: CFrame
default:
summary: |
A `Datatype.CFrame` value indicating the updated CFrame of the body
part that moved.
tags:
- Deprecated
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.WindowFocused
summary: |
Fires when the window of the Roblox client gains focus on the user's
screen.
description: |
This event fires when the window of the Roblox client gains focus,
typically when it is maximized or actively opened by the user. Can be used
alongside `Class.UserInputService.WindowFocusReleased|WindowFocusReleased`
to track when the client loses focus on a user's screen.
code_samples: []
parameters: []
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
- name: UserInputService.WindowFocusReleased
summary: |
Fires when the window of the Roblox client loses focus on the user's
screen.
description: |
This event fires when the window of the Roblox client loses focus,
typically when it is minimized by the user. Can be used alongside
`Class.UserInputService.WindowFocused|WindowFocused` to track when the
client gains focus on a user's screen.
code_samples:
- UserInputService-Window-Focus-Client
- UserInputService-Window-Focus-Server
parameters: []
tags: []
deprecation_message: ''
security: None
capabilities:
- Input
callbacks: []