XInput.ahk wraps a few key functions of XInput, a.k.a. the Microsoft Common Controller API. It provides the following capabilities not otherwise accessible to scripts:
- The official drivers report to Windows one axis for both analog triggers, making it impossible to detect when both triggers are pulled at once. XInput allows one to retrieve the state of each analog trigger individually.
- Set level of controller vibration - left and right motor speeds.
- Detect input on attached messenger kits (mini keyboards which can be attached to a controller).
- Retrieve battery levels of wireless controllers.
- Access the audio input/output of a given controller's headset.
This should be included in recent DirectX run-times.
Usage notes for each function are included in XInput.ahk.
XInput.ahk for AutoHotkey 1.1
This version uses objects, so AutoHotkey 1.1 (AutoHotkey_L) is required.
; Example: Control the vibration motors using the analog triggers of each controller. XInput_Init() Loop { Loop, 4 { if State := XInput_GetState(A_Index-1) { LT := State.bLeftTrigger RT := State.bRightTrigger XInput_SetState(A_Index-1, LT*257, RT*257) } } Sleep, 100 }XInput.ahk for AutoHotkey 1.0
This version uses JSON strings, and should work on any version of AutoHotkey. The example below requires json().
; Example: Control the vibration motors using the analog triggers of each controller. XInput_Init() Loop { Loop, 4 { if XInput_GetState(A_Index-1, State)=0 { LT := json(State,"bLeftTrigger") RT := json(State,"bRightTrigger") XInput_SetState(A_Index-1, LT*257, RT*257) } } Sleep, 100 }XInput.ahk is basically public domain.