util.input.is_pressed

Client

Checks whether a keyboard or mouse button is currently held down


Syntax

local result = util.input.is_pressed(
    key
)

Parameters

TypeNameDescription
util.input.keykeyKey or button to query

Returns

TypeNameDescription
boolresulttrue if the key or button is currently held down, false otherwise

Examples

Check if the W key is held
if util.input.is_pressed(util.input.key.W) then
    core.engine.print("info", "W is held")
end
Check if the left mouse button is held
if util.input.is_pressed(util.input.key.MOUSE_LEFT) then
    core.engine.print("info", "Left mouse button is held")
end
Check multiple keys for a sprint condition
local moving = util.input.is_pressed(util.input.key.W)
local sprinting = moving and util.input.is_pressed(util.input.key.SHIFT)

core.engine.print("info", "Sprinting:", sprinting)

On this page