Created
July 16, 2023 02:48
-
-
Save ihainan/a35aa27bd9a50f59b29c2bd361979ebe to your computer and use it in GitHub Desktop.
XInputTestV1.ahk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Example: Control the vibration motors using the analog triggers of each controller. | |
#Include <XInput> | |
XInput_Init() | |
Gui, +AlwaysOnTop | |
Gui, Add, Text, w300, Note: For Xbox controller 2013 and newer (anything newer than the Xbox 360 controller), this script can only detect controller events if a window it owns is active (like this one). | |
Gui, Add, Edit, w300 h30 +ReadOnly | |
Gui, Add, Edit, w300 h30 +ReadOnly | |
Gui, Add, Edit, w300 h30 +ReadOnly | |
Gui, Add, Edit, w300 h30 +ReadOnly | |
Gui, Add, Edit, w300 h30 +ReadOnly | |
Gui, Show,, Controller Test Script | |
bitMask(x, y) { | |
if ((x & y) == y) { | |
return 1 | |
} else { | |
return 0 | |
} | |
} | |
; Loop { | |
; Loop 4 { | |
; str := "Available controllers: " | |
; if State := XInput_GetState(A_Index) { | |
; str = % A_Index | |
; } | |
; } | |
; GuiControl,, Edit5, %str% | |
; Sleep 1000 | |
; } | |
Controller_ID = 0 | |
Loop { | |
if State := XInput_GetState(Controller_ID) { | |
sThumbLX := State.sThumbLX | |
sThumbLY := State.sThumbLY | |
sThumbRX := State.sThumbRX | |
sThumbRY := State.sThumbRY | |
bLeftTrigger := State.bLeftTrigger | |
bRightTrigger := State.bRightTrigger | |
GuiControl,, Edit1, sThumbLX: %sThumbLX% sThumbLY: %sThumbLY% sThumbRX: %sThumbRX% sThumbRY: %sThumbRY% bLeftTrigger %bLeftTrigger% bRightTrigger %bRightTrigger% wButtons: %wButtons% | |
wButtons := State.wButtons | |
dwPacketNumber := State.dwPacketNumber | |
; dPads | |
dPadUp := bitMask(wButtons, XINPUT_GAMEPAD_DPAD_UP) | |
dPadDown := bitMask(wButtons, XINPUT_GAMEPAD_DPAD_DOWN) | |
dPadLeft := bitMask(wButtons, XINPUT_GAMEPAD_DPAD_LEFT) | |
dPadRight := bitMask(wButtons, XINPUT_GAMEPAD_DPAD_RIGHT) | |
GuiControl,, Edit2, dPadUp: %dPadUp% dPadDown: %dPadDown% dPadLeft: %dPadLeft% dPadRight: %dPadRight% | |
; A, B, X, Y | |
gamePadA := bitMask(wButtons, XINPUT_GAMEPAD_A) | |
gamePadB := bitMask(wButtons, XINPUT_GAMEPAD_B) | |
gamePadX := bitMask(wButtons, XINPUT_GAMEPAD_X) | |
gamePadY := bitMask(wButtons, XINPUT_GAMEPAD_Y) | |
GuiControl,, Edit3, gamePadA: %gamePadA% gamePadB: %gamePadB% gamePadX: %gamePadX% gamePadY: %gamePadY% | |
; Start, Back, Left Thumb, Right Thumb, Left Thumb | |
startButton := bitMask(wButtons, XINPUT_GAMEPAD_START) | |
backButton := bitMask(wButtons, XINPUT_GAMEPAD_BACK) | |
leftThumbClick := bitMask(wButtons, XINPUT_GAMEPAD_LEFT_THUMB) | |
rightThumbClick := bitMask(wButtons, XINPUT_GAMEPAD_RIGHT_THUMB) | |
leftShoulder := bitMask(wButtons, XINPUT_GAMEPAD_LEFT_SHOULDER) | |
rightShoulder := bitMask(wButtons, XINPUT_GAMEPAD_RIGHT_SHOULDER) | |
GuiControl,, Edit4, startButton: %startButton% backButton: %backButton% leftThumbClick: %leftThumbClick% rightThumbClick: %rightThumbClick% leftShoulder: %leftShoulder% rightShoulder: %rightShoulder% | |
} | |
Sleep 100 | |
} | |
GuiClose: | |
ExitApp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment