How to get Joystick to Track and Image Topic is solved
Posted: 08 Mar 2018, 07:40
Hi All,
So I have an AHK Script that tracks an Image.bmp file for my game. Works perfectly Fine on Mouse and Keyboard.
I'm trying to get the same script to track when I'm using Joystick. Ive changed the variables and its not working. I'm hoping someone can help me.
Updates:
1. I changed all the X and Y axis to Z and R Axis as per the Controller
2. Still not working
Here is a copy of the script I used:
; <COMPILER: v1.1.24.01>
#SingleInstance, Force
#Persistent
#NoEnv
#Warn
SendMode, Input
SetWorkingDir, %A_ScriptDir%
DirZ := 0
DirR := 0
F5::
#Persistent
#KeyHistory, 0
#NoEnv
#HotKeyInterval 1
#MaxHotkeysPerInterval 9999
#InstallKeybdHook
#InstallMouseHook
#UseHook
#SingleInstance, Force
SetKeyDelay,-1, 1
SetControlDelay, -1
SetMouseDelay, -1
SetWinDelay,-1
SetDefaultMouseSpeed, 0
SendMode, InputThenPlay
SetBatchLines,-1
ListLines, Off
CoordMode, Joystick, client
PID := DllCall("GetCurrentProcessId")
Process, Priority, %PID%, High
AntiShakeZ := A_ScreenHeight/2
AntiShakeR := A_ScreenHeight/2
ZeroZ := A_Screenwidth/2
ZeroR := A_Screenheight/2
CFovZ := A_Screenwidth
CFovR := A_Screenheight
ScanL := ZeroZ
ScanT := ZeroR
ScanR := ZeroZ
ScanB := ZeroR
NearAimScanL := ZeroZ - AntiShakeZ
NearAimScanT := ZeroR - AntiShakeR
NearAimScanR := ZeroZ + AntiShakeZ
NearAimScanB := ZeroR + AntiShakeR
AScanL := ZeroZ - CFovZ
AScanR := ZeroZ + CFovZ
AScanT := ZeroR - CFovR
AScanB := ZeroR + CFovR
aim_lock := 1
inicount := 9
fileread,settings,settings.ini
stringsplit,settings,settings,`n
if !(fileexist("settings.ini")) || (settings0-3 != inicount)
{
iniread,rx,settings.ini,settings,sen, 9.5
iniread,xrange,settings.ini,settings,FovX, 4.5
iniread,yrange,settings.ini,settings,FovY, 3.5
iniread,xa,settings.ini,settings,AimX, 70
iniread,xy,settings.ini,settings,AimY, 41
}
Soundbeep, 750, 500
Loop,
{
GetKeyState, Mouse1, RButton, P
GetKeyState("Joy1" , "D")
if ( Mouse1 == "D" )
{
GoSub JoyMoves1
}
GetKeyState, Key1, F5, P
if ( Key1 == "D")
{
Soundbeep
break
}
}
JoyMoves1:
imageSearch, AimPixelZ, AimPixelR, 0 + (A_Screenwidth * (xrange/10)), 0 + (A_Screenheight * (yrange/10)), A_Screenwidth - (A_Screenwidth * (xrange/10)), A_Screenheight - (A_Screenheight * (yrange / 10)), healthbar.bmp
if(AimPixelZ != "" && AimPixelR != "")
{
GoSub GetAimOffset
GoSub GetAimMoves
}
else
imageSearch, AimPixelX, AimPixelY, 0 + (A_Screenwidth * (xrange/10)), 0 + (A_Screenheight * (yrange/10)), A_Screenwidth - (A_Screenwidth * (xrange/10)), A_Screenheight - (A_Screenheight * (yrange / 2)), *4 orangehealthbar.bmp
if(AimPixelX != "" && AimPixelY != "")
{
GoSub GetAimOffset
GoSub GetAimMoves
}
else
{
imageSearch, AimPixelX, AimPixelY, 0 + (A_Screenwidth * (xrange/10)), 0 + (A_Screenheight * (yrange/10)), A_Screenwidth - (A_Screenwidth * (xrange/10)), A_Screenheight - (A_Screenheight * (yrange / 10)), yellowhealthbar.bmp
if(AimPixelX != "" && AimPixelY != "")
{
GoSub GetAimOffset
GoSub GetAimMoves
}
}
Return
GetAimOffset:
Gui,Submit, Nohide
AimZ := AimPixelZ - ZeroZ +xa
AimR := AimPixelR - ZeroR +xy
if ( AimZ+10 > 0)
{
DirZ := rx / 10
}
else if ( AimZ+5 > 0)
{
DirZ := rx / 15
}
if ( AimZ+10 < 0)
{
DirZ := (-rx) / 10
}
else if ( AimZ+5 < 0)
{
DirZ := (-rx) / 15
}
if ( AimR+.25 > 0 )
{
DirR := rx /13
}
if ( AimR+.25 < 0 )
{
DirR := (-rx) /13
}
AimOffsetZ := AimZ * DirZ
AimOffsetR := AimR * DirR
Return
GetAimMoves:
RootZ := Ceil(( AimOffsetZ ** ( 1 )))
RootR := Ceil(( AimOffsetR ** ( 1 )))
MoveZ := RootZ * DirR
MoveR := RootR * DirR
DllCall("joy_event", uint, 1, int, MoveZ*1.1, int, MoveR*1.1, uint, 0, int, 0)
Return
F6:: exitapp
So I have an AHK Script that tracks an Image.bmp file for my game. Works perfectly Fine on Mouse and Keyboard.
I'm trying to get the same script to track when I'm using Joystick. Ive changed the variables and its not working. I'm hoping someone can help me.
Updates:
1. I changed all the X and Y axis to Z and R Axis as per the Controller
2. Still not working
Here is a copy of the script I used:
; <COMPILER: v1.1.24.01>
#SingleInstance, Force
#Persistent
#NoEnv
#Warn
SendMode, Input
SetWorkingDir, %A_ScriptDir%
DirZ := 0
DirR := 0
F5::
#Persistent
#KeyHistory, 0
#NoEnv
#HotKeyInterval 1
#MaxHotkeysPerInterval 9999
#InstallKeybdHook
#InstallMouseHook
#UseHook
#SingleInstance, Force
SetKeyDelay,-1, 1
SetControlDelay, -1
SetMouseDelay, -1
SetWinDelay,-1
SetDefaultMouseSpeed, 0
SendMode, InputThenPlay
SetBatchLines,-1
ListLines, Off
CoordMode, Joystick, client
PID := DllCall("GetCurrentProcessId")
Process, Priority, %PID%, High
AntiShakeZ := A_ScreenHeight/2
AntiShakeR := A_ScreenHeight/2
ZeroZ := A_Screenwidth/2
ZeroR := A_Screenheight/2
CFovZ := A_Screenwidth
CFovR := A_Screenheight
ScanL := ZeroZ
ScanT := ZeroR
ScanR := ZeroZ
ScanB := ZeroR
NearAimScanL := ZeroZ - AntiShakeZ
NearAimScanT := ZeroR - AntiShakeR
NearAimScanR := ZeroZ + AntiShakeZ
NearAimScanB := ZeroR + AntiShakeR
AScanL := ZeroZ - CFovZ
AScanR := ZeroZ + CFovZ
AScanT := ZeroR - CFovR
AScanB := ZeroR + CFovR
aim_lock := 1
inicount := 9
fileread,settings,settings.ini
stringsplit,settings,settings,`n
if !(fileexist("settings.ini")) || (settings0-3 != inicount)
{
iniread,rx,settings.ini,settings,sen, 9.5
iniread,xrange,settings.ini,settings,FovX, 4.5
iniread,yrange,settings.ini,settings,FovY, 3.5
iniread,xa,settings.ini,settings,AimX, 70
iniread,xy,settings.ini,settings,AimY, 41
}
Soundbeep, 750, 500
Loop,
{
GetKeyState, Mouse1, RButton, P
GetKeyState("Joy1" , "D")
if ( Mouse1 == "D" )
{
GoSub JoyMoves1
}
GetKeyState, Key1, F5, P
if ( Key1 == "D")
{
Soundbeep
break
}
}
JoyMoves1:
imageSearch, AimPixelZ, AimPixelR, 0 + (A_Screenwidth * (xrange/10)), 0 + (A_Screenheight * (yrange/10)), A_Screenwidth - (A_Screenwidth * (xrange/10)), A_Screenheight - (A_Screenheight * (yrange / 10)), healthbar.bmp
if(AimPixelZ != "" && AimPixelR != "")
{
GoSub GetAimOffset
GoSub GetAimMoves
}
else
imageSearch, AimPixelX, AimPixelY, 0 + (A_Screenwidth * (xrange/10)), 0 + (A_Screenheight * (yrange/10)), A_Screenwidth - (A_Screenwidth * (xrange/10)), A_Screenheight - (A_Screenheight * (yrange / 2)), *4 orangehealthbar.bmp
if(AimPixelX != "" && AimPixelY != "")
{
GoSub GetAimOffset
GoSub GetAimMoves
}
else
{
imageSearch, AimPixelX, AimPixelY, 0 + (A_Screenwidth * (xrange/10)), 0 + (A_Screenheight * (yrange/10)), A_Screenwidth - (A_Screenwidth * (xrange/10)), A_Screenheight - (A_Screenheight * (yrange / 10)), yellowhealthbar.bmp
if(AimPixelX != "" && AimPixelY != "")
{
GoSub GetAimOffset
GoSub GetAimMoves
}
}
Return
GetAimOffset:
Gui,Submit, Nohide
AimZ := AimPixelZ - ZeroZ +xa
AimR := AimPixelR - ZeroR +xy
if ( AimZ+10 > 0)
{
DirZ := rx / 10
}
else if ( AimZ+5 > 0)
{
DirZ := rx / 15
}
if ( AimZ+10 < 0)
{
DirZ := (-rx) / 10
}
else if ( AimZ+5 < 0)
{
DirZ := (-rx) / 15
}
if ( AimR+.25 > 0 )
{
DirR := rx /13
}
if ( AimR+.25 < 0 )
{
DirR := (-rx) /13
}
AimOffsetZ := AimZ * DirZ
AimOffsetR := AimR * DirR
Return
GetAimMoves:
RootZ := Ceil(( AimOffsetZ ** ( 1 )))
RootR := Ceil(( AimOffsetR ** ( 1 )))
MoveZ := RootZ * DirR
MoveR := RootR * DirR
DllCall("joy_event", uint, 1, int, MoveZ*1.1, int, MoveR*1.1, uint, 0, int, 0)
Return
F6:: exitapp