Joystick JoyPOV to a Single Click. Topic is solved

Ask gaming related questions
Dumitas
Posts: 21
Joined: 14 Dec 2017, 21:32

Joystick JoyPOV to a Single Click.

14 Dec 2017, 21:40

Hi everyone, Im using my joystick to play a game that requiere mouse and keyboard only and I'm having a little issue with JoyPOV and click.

Code: Select all

#Persistent

SetTimer, WatchAxis, 5
SetTimer, WatchPOV, 5
return


WatchPOV:
GetKeyState, POV, JoyPOV
KeyToHoldDownPrev = %KeyToHoldDown%

if POV < 0 
    KeyToHoldDown = 
else if POV = 0
    KeyToHoldDown = 
; Those 3 are the problem, Im not using up arrow.
else if POV = 9000
    Send {Click, 465, 540}	
else if POV = 18000
    Send {Click, 418, 591}
else if POV = 27000 
    Send {Click, 379, 540}
	
WatchAxis:
GetKeyState, JoyX, JoyX,
GetKeyState, JoyY, JoyY, 
KeyToHoldDownPrev = %KeyToHoldDown%  

if JoyY < 49
    KeyToHoldDown = w
else if JoyX < 49
    KeyToHoldDown = a
else if JoyY > 51
    KeyToHoldDown = s
else if JoyX > 51
    KeyToHoldDown = d
   else
    KeyToHoldDown =
	
if KeyToHoldDown = %KeyToHoldDownPrev% 
    return 
	
SetKeyDelay -1  
if KeyToHoldDownPrev   
    Send, {%KeyToHoldDownPrev% up} 
if KeyToHoldDown  
    Send, {%KeyToHoldDown% down}
 return


	
 
 
Joy5::MouseClick, left, 430, 535 ; L1
Joy6::MouseClick, left, 580, 535 ; L2
Joy7::MouseClick, left, 430, 580 ; R1
Joy8::MouseClick, left, 580, 580 ; R2

Joy1::Send f 
Joy4::Send b
Joy3::Send {Space}
Joy2::MouseClick, left, 940, 605

Using buttoms Joy(number) its easy to click anywhere without any problem, but with JoyPOV I don't know how to use "MouseClick" but click instead, the problem is that as long as I keep the JoyPOV (Joystick arrows) pressed it keep clicking.

I need to change JoyPOV so it click once.




Thank you in advance.


PS: I don't entirely understand the code, I made it with different tutorial on this forum and the guides on ahk page, so If you find something unnecessary or that can be improved feel free to do it so.
User avatar
evilC
Posts: 4372
Joined: 27 Feb 2014, 12:30

Re: Joystick JoyPOV to a Single Click.  Topic is solved

15 Dec 2017, 07:18

A couple of problems here:

Code: Select all

WatchPOV:
GetKeyState, POV, JoyPOV
KeyToHoldDownPrev = %KeyToHoldDown%

if POV < 0 
    KeyToHoldDown = 
else if POV = 0
    KeyToHoldDown = 
; Those 3 are the problem, Im not using up arrow.
else if POV = 9000
    Send {Click, 465, 540}	
else if POV = 18000
    Send {Click, 418, 591}
else if POV = 27000 
    Send {Click, 379, 540}
	
WatchAxis:
You have no return statement after the end of WatchPOV, so your WatchPOV timer is ALSO triggering WatchAxis.

SetTimer, WatchPOV, 5 AHK does not support timers of 5. The actual tick rate of the timer will be the minimum timer period, which varies by PC and is typically ~10ms

In order to solve your repeated clicking issue, you need to do like this:

Code: Select all

LastPOV := -1
SetTimer, WatchPOV, 5
return

WatchPOV:
GetKeyState, POV, JoyPOV
if (LastPOV == POV)  ; If POV did not change, abort
    return
LastPOV := POV ; Store state of POV in LastPOV, so we can check if it changed
KeyToHoldDownPrev = %KeyToHoldDown%

if POV < 0 
    KeyToHoldDown = 
else if POV = 0
    KeyToHoldDown = 
; Those 3 are the problem, Im not using up arrow.
else if POV = 9000
    Send {Click, 465, 540}	
else if POV = 18000
    Send {Click, 418, 591}
else if POV = 27000 
    Send {Click, 379, 540}
return ; ALWAYS put a return at the end of your labels, else execution will not stop here!
Dumitas
Posts: 21
Joined: 14 Dec 2017, 21:32

Re: Joystick JoyPOV to a Single Click.

15 Dec 2017, 13:23

Works perfect, thank you very much.

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 5 guests