#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#InstallKeybdHook
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetBatchLines, -1
Setkeydelay, 60, 60
Thread, interrupt, 0 ; Make all threads always-interruptible.
SetTimer, KWS, 30
; Auto-detect the Joystick Device Number
; ======================================
; If you want to unconditionally use a specific joystick number, change
; the following value from 0 to the number of the joystick (1-16).
; A value of 0 causes the joystick number to be auto-detected.
Joy = 0
if Joy <= 0
{
Loop 16 ; Query each joystick number to find out which ones exist.
{
GetKeyState, JoyName, %A_Index%JoyName
if JoyName <>
{
Joy = %A_Index%
break
}
}
if Joy <= 0
{
MsgBox The system does not appear to have any joysticks.
ExitApp
}
}
; Cancel KWS when changing fire group (bound to my 'f' key) or engaging FSD (bound to my 'e' key)
~f::
~e::
if KWS
Send {\ Up}
KWS := 0
return
#IfWinActive
; **************************************
; TIMERS
; **************************************
KWS:
if not ( GetKeystate("Control") or GetKeystate("Alt") ) {
GetKeyState, Joy5, %Joy%Joy5
if ( Joy5 ="D" ) {
KeyWait, %Joy%Joy5 ; Wait for key to be released
if ( KWS := !KWS )
; '\' is my secondary keybind for secondary fire. My primary keybind for secondary fire is Joy5,
; but you can't send Joystick button presses in AHK. So, one of your keybinds for secondary fire
; needs to be a keyboard or mouse key.
Send {\ Down}
else
Send {\ Up}
}
}
else { ; Cancel KWS if modifier key (Ctrl or Alt) pressed
if KWS
Send {\ Up}
KWS := 0
}
return