UserInputService

UserInputService : Instance

Properties

Methods

Events

TouchStarted

Fires when the user begins touching the screen of a touch-enabled device.

Parameters

InputObject InputObject

The touch input object containing data about the touch event.

bool bGameProcessed

Indicates if the touch event was already processed by the game.

Code Samples

local UserInputService = game:GetService("UserInputService")

local function OnScreenTouchStart(input, _gameProcessed)
    local keyCode = input.KeyCode        
    local inputState = input.UserInputState 
    local inputType = input.UserInputType   
    local delta = input.Delta
    local pos = input.Position    
end
UserInputService.TouchStarted:Connect(OnScreenTouchStart)

TouchMoved

Fires when the user's touch moves across the screen.

Parameters

InputObject InputObject

The touch input object containing data about the movement.

bool bGameProcessed

Indicates if the movement event was already processed by the game.

Code Samples

local UserInputService = game:GetService("UserInputService")

local function OnScreenTouchMove(input, _gameProcessed)
    local keyCode = input.KeyCode        
    local inputState = input.UserInputState 
    local inputType = input.UserInputType   
    local delta = input.Delta
    local pos = input.Position 
end
UserInputService.TouchMoved:Connect(OnScreenTouchMove)

TouchEnded

Fires when the user lifts their finger and stops touching the screen of a touch-enabled device.

Parameters

InputObject InputObject

The touch input object containing data about the end of the touch.

bool bGameProcessed

Indicates if the touch event was already processed by the game.

Code Samples

local UserInputService = game:GetService("UserInputService")

local function OnScreenTouchEnd(input, _gameProcessed)
    local keyCode = input.KeyCode        
    local inputState = input.UserInputState 
    local inputType = input.UserInputType   
    local delta = input.Delta
    local pos = input.Position 
end
UserInputService.TouchEnded:Connect(OnScreenTouchEnd)

InputBegan

Fires when the user begins interacting with an input device (e.g., a key or mouse button is pressed).

Parameters

InputObject InputObject

The input object containing data about the interaction.

bool bGameProcessed

Indicates if the input event was already processed by the game.

Code Samples

local function OnScreenTouchStart(input, _gameProcessed)
    local keyCode = input.KeyCode        
    local inputState = input.UserInputState 
    local inputType = input.UserInputType   
    local delta = input.Delta
    local pos = input.Position    
end
UserInputService.InputBegan:Connect(OnScreenTouchStart)

InputChanged

Fires when the user changes an input, such as moving a mouse or dragging on a touch screen.

Parameters

InputObject InputObject

The input object containing data about the change in input.

bool bGameProcessed

Indicates if the input event was already processed by the game.

Code Samples

local UserInputService = game:GetService("UserInputService")

local function OnScreenTouchMove(input, _gameProcessed)
    local keyCode = input.KeyCode        
    local inputState = input.UserInputState 
    local inputType = input.UserInputType   
    local delta = input.Delta
    local pos = input.Position 
end
UserInputService.InputChanged:Connect(OnScreenTouchMove)

InputEnded

Fires when the user stops interacting with an input device (e.g., a key or mouse button is released).

Parameters

InputObject InputObject

The input object containing data about the end of the interaction.

bool bGameProcessed

Indicates if the input event was already processed by the game.

Code Samples

local UserInputService = game:GetService("UserInputService")

local function OnScreenTouchEnd(input, _gameProcessed)
    local keyCode = input.KeyCode        
    local inputState = input.UserInputState 
    local inputType = input.UserInputType   
    local delta = input.Delta
    local pos = input.Position 
end
UserInputService.InputEnded:Connect(OnScreenTouchEnd)

Last updated