Difference between revisions of "Lua:getXBox360ControllerState"

From Cheat Engine
Jump to navigation Jump to search
(Replaced content with '<span style="font-size:25px;color:red">Sorry! Content not available.</span>')
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
<span style="font-size:25px;color:red">Sorry! Content not available.</span>
+
[[Category:Lua]]
 +
{{CodeBox|'''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===
 +
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Parameter
 +
!align="left"|Type
 +
!style="width: 80%;background-color:white;" align="left"|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===
 +
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Field
 +
!align="left"|Type
 +
!style="width: 80%;background-color:white;" align="left"|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===
 +
<pre>
 +
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
 +
</pre>
 +
 
 +
{{LuaSeeAlso}}

Latest revision as of 04:00, 21 June 2026

<> 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[edit]

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

Returns[edit]

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

Return Table Fields[edit]

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[edit]

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[edit]

Lua
Script Engine