PcoWSkbVqDnWTu_dm2ix
Collapse Sidebar

UserInputType

InputObject

UserInputType

Contains a Enum/UserInputType enum that describes the type of user input, such as whether the input is via keyboard, mouse, touch, gamepad, to name a few.

Enums

Name Value Description

MouseButton1

0

The left mouse button.

MouseButton2

1

The right mouse button.

MouseButton3

2

The middle mouse button.

MouseWheel

3

The mouse wheel.

MouseMovement

4

Movement of the mouse.

Touch

7

A tap on the screen from a mobile device.

Keyboard

8

Key press on a keyboard.

Focus

9

The client regaining focus of the Roblox window.

Accelerometer

10

The accelerometer of a mobile device.

Gyro

11

The Gyroscope of a mobile device.

Gamepad1

12

Input from the 1st plugged in Gamepad.

Gamepad2

13

Input from the 2nd plugged in Gamepad.

Gamepad3

14

Input from the 3rd plugged in Gamepad.

Gamepad4

15

Input from the 4th plugged in Gamepad.

Gamepad5

16

Input from the 5th plugged in Gamepad

Gamepad6

17

Input from the 6th plugged in Gamepad.

Gamepad7

18

Input from the 7th plugged in Gamepad.

Gamepad8

19

Input from the 8th plugged in Gamepad.

TextInput

20

Input of Text into a text-based GuiObject. Normally this is only a TextBox.

None

21

Unknown UserInputType.

See also

  • InputObject/Delta
  • InputObject/KeyCode
  • InputObject/Position
  • InputObject/UserInputState


Code Samples


Create a Custom CameraScript

By default, Roblox relies on a LocalScript, described [here][1], to control the user’s camera. However, this script can be overridden with a custom CameraScript. The example below demonstrates how to create a custom script to control the user’s camera using many of the UserInputService events.

The script is broken into two parts:

  1. Mobile camera events, which rely on touch events
  2. Non-mobile camera events, which rely on keyboard input and tracking the user’s movement

First, the camera script needs utility functions to setup the camera and set its Camera/CameraType|CameraType to Scriptable so that the script can control the camera. It also needs a function to update the camera when it moves, rotates, and zooms.

Using touch events allows us to track user input as they interact with the touchscreen on their mobile device. These events allow us to handle camera movement, rotation, and zoom.

The second half of the code sample adds camera support for players on desktop devices. When input begans, the function Input() checks that the state of the input is Enum/UserInputState|Enum.UserInputState.Begin to ignore all keypress inputs other than when the user first presses a key down. When the user presses I and O the camera zooms in and out. When the presses down and moves their left mouse button, the script Enum/MouseBehavior|locks the player’s mouse by changing the UserInputService/MouseBehavior property. The camera rotates according to the mouse’s UserInputService/GetMouseDelta|change in screen position. When the player moves their character, the camera moves with them.

All of the parts discussed above are combined and shown in the code sample below.


Handling InputBegan

The following example demonstrates one of many usage examples of handling user input from InputBegan depending on its type.


Handling InputChanged

The following example demonstrates one of many usage examples of handling user input from InputChanged depending on its type.