Lua:getXBox360ControllerState

From Cheat Engine
Revision as of 04:00, 21 June 2026 by Leunsel (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
<> Function

function getXBox360ControllerState(ControllerID) : table

Fetches the state of a connected Xbox 360 controller.

If successful, this function returns a table containing the current controller state, including button states, trigger values, thumbstick positions, the controller ID, and the packet number.

The packet number can be used to detect whether the controller state has changed since the last call.

Function Parameters

Parameter Type Description
ControllerID Integer (optional) The ID of the controller to fetch the state from. Valid values range from 0 to 3.

Returns

table — A table containing the current controller state on success.

Return Table Fields

Field Type Description
ControllerID Integer The ID of the controller. Valid values range from 0 to 3.
PacketNumber Integer The packet ID of the controller state. This can be used to detect state changes.
GAMEPAD_DPAD_UP Boolean True if D-PAD Up is pressed.
GAMEPAD_DPAD_DOWN Boolean True if D-PAD Down is pressed.
GAMEPAD_DPAD_LEFT Boolean True if D-PAD Left is pressed.
GAMEPAD_DPAD_RIGHT Boolean True if D-PAD Right is pressed.
GAMEPAD_START Boolean True if the Start button is pressed.
GAMEPAD_BACK Boolean True if the Back button is pressed.
GAMEPAD_LEFT_THUMB Boolean True if the left thumbstick button is pressed.
GAMEPAD_RIGHT_THUMB Boolean True if the right thumbstick button is pressed.
GAMEPAD_LEFT_SHOULDER Boolean True if the left shoulder button is pressed.
GAMEPAD_RIGHT_SHOULDER Boolean True if the right shoulder button is pressed.
GAMEPAD_A Boolean True if the A button is pressed.
GAMEPAD_B Boolean True if the B button is pressed.
GAMEPAD_X Boolean True if the X button is pressed.
GAMEPAD_Y Boolean True if the Y button is pressed.
LeftTrigger Integer The value of the left trigger. The value ranges from 0 to 255.
RightTrigger Integer The value of the right trigger. The value ranges from 0 to 255.
ThumbLeftX Integer The horizontal position of the left thumbstick. The value ranges from -32768 to 32767.
ThumbLeftY Integer The vertical position of the left thumbstick. The value ranges from -32768 to 32767.
ThumbRightX Integer The horizontal position of the right thumbstick. The value ranges from -32768 to 32767.
ThumbRightY Integer The vertical position of the right thumbstick. The value ranges from -32768 to 32767.

Examples

local state = getXBox360ControllerState()

if state ~= nil then
  print("Controller ID: " .. state.ControllerID)
  print("Packet number: " .. state.PacketNumber)

  if state.GAMEPAD_A then
    print("A button is pressed")
  end

  print("Left trigger: " .. state.LeftTrigger)
  print("Left thumbstick X: " .. state.ThumbLeftX)
  print("Left thumbstick Y: " .. state.ThumbLeftY)
end

See also

Lua
Script Engine