Event

sandbox:key_input

Client

Fired when a keyboard key or mouse button is pressed or released

Signal

"sandbox:key_input"

Arguments

TypeNameDescription
util.input.keykeycodeKey or mouse button identifier
boolpressedtrue if pressed, false if released

Fires for both keyboard keys and mouse buttons.

  • Key-repeat echoes are suppressed — only the initial press and release are reported.
  • If the engine console intercepts a key on press, that key will not fire this signal.
  • Refer to the util.input.key enum for keycode values.

Example

Detect spacebar press
util.event.on("sandbox:key_input", function(keycode, pressed)
    if keycode == util.input.key.SPACE and pressed then
        core.engine.print("info", "Space pressed")
    end
end)
Detect left mouse button
util.event.on("sandbox:key_input", function(keycode, pressed)
    if keycode == util.input.key.MOUSE_LEFT then
        core.engine.print("info", "LMB " .. (pressed and "down" or "up"))
    end
end)

On this page