Need to send NUMPAD 9 when joystick UP and Right

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
baba_anubis
Posts: 10
Joined: 08 Dec 2016, 19:39

Need to send NUMPAD 9 when joystick UP and Right

12 Oct 2021, 13:15

Hi, I hope someone can help me...

I need a script which does the following:

When I move the joystick up I want it to send NUMPAD 8

When I move the Joystick Right I want it so send NUMPAD 6

When I move the Joystick UP RIGHT I want it so send Numpad 9

I need it for some old game, please bare in mind that this is 2 player game so I want to have a unique script for each joystick.


Here is a script which I always duplicate for diffrent games with diffrent keys...however this one works great but it doesn't take into account to send NUMPAD 9 when I move the joystick UP & RIGHT

(I didn't write this script, I believe someone here helped me long ago...not sure...)

Code: Select all

JoyNum = 1 ; put a number if you have more than 1 joystick
XLowKey = left
XHighKey = right
YLowKey = up
YHighKey = down
Axis = XY ; these are the axises we're using
RepeatRate = 500 ~ 50 ; slowest and fastest delays between repeats (in ms)
; WARNING: no newbies below this line
#Persistent
SendMode, Input ; es muy rapido
StringSplit, r, RepeatRate, ~, %A_Space% ; moves the two numbers from
; RepeatRate into r1 and r2 for use later in the script
SetTimer, WatchAxis, 10
WatchAxis:
Loop, Parse, Axis ; Sets the variable A_LoopField to the current axis
; this next if statement is the kicker, it is one expression evaluated like so:
; first, lets say that we're dealing with the X axis, so the expression resolves
; !qX first, lets say it resolves to 1 (which it does when qX is either empty or 0)
; then, the getkeystate is resolved, and the JoyX axis is retrieved. by default
; joystick axises go from 0 to 100, with 50 being in the middle, so this part
; takes that number, subtracts 50 from it, and stores the result in jX
; then the absolute value of jX is stored in dX
; then dX is compared to the number 7, and if it is greater, then a 1 gets
; stored in qX, otherwise, a 0 gets stored in qX
; remember how the expression already resolved !qX at the beginning?
; well, !qX will be equal to the new value of qX if and only if that
; value changes from 0 to 1 or from 1 to 0, thusly, the overall statement
; only resolves to 'true' when the axis changes between "close to center" and
; "not close to center"
If (!q%A_LoopField%) = q%A_LoopField% := (7 < d%A_LoopField% := ""
. Abs(j%A_LoopField% := GetKeyState(joynum "Joy" A_LoopField, "P") - 50))
{
; so, this block will execute when the axis changes status
; and the variable qX can be thought of as meaning "The axis is not close to the center"
; So, the next if statement checks whether qX is true, and if it is, then
; send a certan keydown event. That certan key is chosen by the ternary operator
; and is stored in the variable XKey. The ternary operator checks whether
; jX is above or below zero (remember when the axis position was stored in jX?)
   IfEqual, q%A_LoopField%, 1, Send, % "{Blind}{"
   . (%A_LoopField%Key := j%A_LoopField%<0 ? ""
   . %A_LoopField%LowKey : %A_LoopField%HighKey) " DownTemp}"
; But, if qX is not 1 (if the axis is close to center", then
; release the key that was previously held down
   Else Send % "{Blind}{" %A_LoopField%Key " Up}"
; update a variable to hold a time that we'll refer to as 'then'
   Delay%A_LoopField% := A_TickCount
}
; This next line will execute if, during this particular running of
; this subroutine, the current axis has not changed between being
; "close to the center" and "not close to the center"
; so usually this line gets executed (about 99.9% of the time)
; Anyways, the first if command checks whether the current axis is
; "not close to the center", which is the first part of checking whether
; to repeat a keystroke. Then it checks A_TickCount, which, in a certain
; sense, can be thought of as being equal to 'now'. So, the next part
; compares 'now' to 'then' plus a certain amount, and if it is greater
; then enough time has elapsed between 'then' and 'now' to allow another
; keystroke to be sent. That certain number is between the two numbers
; defined above in the RepeatRate variable
Else IfEqual, q%A_LoopField%, 1, IfGreater, A_TickCount, % ""
. Delay%A_LoopField% + r1 - ((d%A_LoopField%-8)/42)*(r1-r2)
{
;   Send % "{Blind}{" %A_LoopField%Key " Up}" ; uncomment to activate full key repeat
; typical keyboard repeating is just a series of keydown events. Some games
; want an 'up' event before they'll recognize that the key is being spammed
; usually this is not an issue unless you need true rapid-fire for these keys
   Send % "{Blind}{" %A_LoopField%Key " DownTemp}"
; update a variable to hold a time that we'll refer to as 'then' next time around
   Delay%A_LoopField% := A_TickCount
}
return


1joy1::
Send {; down}   ; Press the RALT down.
SetTimer, WaitFor1joy1, 50  ; Reduce the number 30 to 20 or 10 to send keys faster. Increase it to send slower.
return

WaitFor1joy1:
if not GetKeyState("1joy1")  ; The button has been released.
{
    Send {; up}  ; Release the RALT.
    SetTimer, WaitFor1joy1, off  ; Stop monitoring the button.
    return
}
; Since above didn't "return", the button is still being held down.
Send {; down}  ; Send another RALT keystroke.
return
Thank you


Update I tried this code: NUMPAD 8, 6, 4 , 2 work, NUMPAD 9 doesn't....

Code: Select all

JoyNum = 1 ; put a number if you have more than 1 joystick
#Persistent  ; Keep this script running until the user explicitly exits it.
SetTimer, WatchAxis, 5
return

WatchAxis:
JoyX := GetKeyState("JoyX")  ; Get position of X axis.
JoyY := GetKeyState("JoyY")  ; Get position of Y axis.
KeyToHoldDownPrev := KeyToHoldDown  ; Prev now holds the key that was down before (if any).

if (JoyX > 70)
    KeyToHoldDown := "NUMPAD6"
else if (JoyX < 30)
    KeyToHoldDown := "NUMPAD4"
else if (JoyY > 70)
     KeyToHoldDown := "NUMPAD2"
else if (JoyY < 30)
    KeyToHoldDown := "NUMPAD8"
else if (JoyX > 70 and JoyY < 30)
    KeyToHoldDown := "NUMPAD9"
else
    KeyToHoldDown := ""

if (KeyToHoldDown = KeyToHoldDownPrev)  ; The correct key is already down (or no key is needed).
    return  ; Do nothing.

; Otherwise, release the previous key and press down the new key:
SetKeyDelay -1  ; Avoid delays between keystrokes.
if KeyToHoldDownPrev   ; There is a previous key to release.
    Send, {%KeyToHoldDownPrev% up}  ; Release it.
if KeyToHoldDown   ; There is a key to press down.
    Send, {%KeyToHoldDown% down}  ; Press it down.
return
Last edited by baba_anubis on 13 Oct 2021, 12:53, edited 2 times in total.
baba_anubis
Posts: 10
Joined: 08 Dec 2016, 19:39

Re: Need to send NUMPAD 9 when joystick UP and Right

13 Oct 2021, 03:27

OK...
So I was able to solve it... (Please note, that the notes inside the code, probably not accurate, since I didn't update it)
Really happy about the results :P

Here are the scripts in case someone will be interested:

Player 1 Script:

Code: Select all

#Persistent  ; Keep this script running until the user explicitly exits it.
SetTimer, WatchPOV, 5
return


WatchPOV: 
GetKeyState, POV, 1JoyPOV  ; Get position of the POV control. 
Key1ToHoldDownPrev = %Key1ToHoldDown% 
Key2ToHoldDownPrev = %Key2ToHoldDown% 
; Each "Prev" variable now holds the key that was down before (if any). 

; Some joysticks might have a smooth/continous POV rather than one in fixed increments. 
; To support them all, check for ranges: 
if POV < 0   ; No angle to report
{ 
   Key1ToHoldDown = 
} 
else if POV between 35000 and 36000                 ; 337.5 to 360 degrees: Forward 
{ 
   Key1ToHoldDown = Numpad8 
} 
else if POV between 0 and 1000      ; 0 to 22.5 degrees: Forward 
{ 
   Key1ToHoldDown = Numpad8 
   Key2ToHoldDown = 
} 
else if POV between 1000 and 8000   ; Up+Right 
{ 
   Key1ToHoldDown = Numpad9

} 
else if POV between 8000 and 11000  ; Right 
{ 
   Key1ToHoldDown = Numpad6
} 
else if POV between 11000 and 17000 ; Down+Right 
{ 
   Key1ToHoldDown = Numpad3
} 
else if POV between 17000 and 19000 ; Down 
{ 
   Key1ToHoldDown = Numpad2 
} 
else if POV between 19000 and 26000 ; Down+Left 
{ 
   Key1ToHoldDown = Numpad1 
} 
else if POV between 26000 and 28000 ; Left 
{ 
   Key1ToHoldDown = Numpad4 
} 
else if POV between 28000 and 35000 ; Up+Left 
{ 
   Key1ToHoldDown = Numpad7
} 

SetKeyDelay -1  ; Avoid delays between keystrokes. 

if Key1ToHoldDown <> %Key1ToHoldDownPrev%  ; Key #1 needs adjusting. 
{ 
   if Key1ToHoldDownPrev <>   ; There is a previous key to release. 
      Send, {%Key1ToHoldDownPrev% up}  ; Release it. 
   if Key1ToHoldDown <>   ; There is a key to press down. 
      Send, {%Key1ToHoldDown% down}  ; Press it down. 
} 
if Key2ToHoldDown <> %Key2ToHoldDownPrev%  ; Key #2 needs adjusting. 
{ 
   if Key2ToHoldDownPrev <>   ; There is a previous key to release. 
      Send, {%Key2ToHoldDownPrev% up}  ; Release it. 
   if Key2ToHoldDown <>   ; There is a key to press down. 
      Send, {%Key2ToHoldDown% down}  ; Press it down. 
} 


WatchAxis:
1JoyX := GetKeyState("1JoyX")  ; Get position of X axis.
1JoyY := GetKeyState("1JoyY")  ; Get position of Y axis.
KeyToHoldDownPrev := KeyToHoldDown  ; Prev now holds the key that was down before (if any).

if (1JoyX > 70 and 1JoyY < 30)
    KeyToHoldDown := "NUMPAD9"
else if (1JoyX > 70 and 1JoyY > 70)
    KeyToHoldDown := "NUMPAD3"
else if (1JoyX < 30 and 1JoyY > 70)
    KeyToHoldDown := "NUMPAD1"
else if (1JoyX < 30 and 1JoyY < 30)
    KeyToHoldDown := "NUMPAD7"
else if (1JoyX > 70)
    KeyToHoldDown := "NUMPAD6"
else if (1JoyX < 30)
    KeyToHoldDown := "NUMPAD4"
else if (1JoyY > 70)
    KeyToHoldDown := "NUMPAD2"
else if (1JoyY < 30)
    KeyToHoldDown := "NUMPAD8"
else
    KeyToHoldDown := ""

if (KeyToHoldDown = KeyToHoldDownPrev)  ; The correct key is already down (or no key is needed).
    return  ; Do nothing.

; Otherwise, release the previous key and press down the new key:
SetKeyDelay -1  ; Avoid delays between keystrokes.
if KeyToHoldDownPrev   ; There is a previous key to release.
    Send, {%KeyToHoldDownPrev% up}  ; Release it.
if KeyToHoldDown   ; There is a key to press down.
    Send, {%KeyToHoldDown% down}  ; Press it down.
return





1joy3::
Send {RSHIFT down}   ; Press the RALT down.
SetTimer, WaitFor1joy3, 50  ; Reduce the number 30 to 20 or 10 to send keys faster. Increase it to send slower.
return

WaitFor1joy3:
if not GetKeyState("1joy3")  ; The button has been released.
{
    Send {RSHIFT up}  ; Release the RALT.
    SetTimer, WaitFor1joy3, off  ; Stop monitoring the button.
    return
}
; Since above didn't "return", the button is still being held down.
Send {RSHIFT down}  ; Send another RALT keystroke.
return

1joy4::
Send {ENTER down}   ; Press the RALT down.
SetTimer, WaitFor1joy4, 50  ; Reduce the number 30 to 20 or 10 to send keys faster. Increase it to send slower.
return

WaitFor1joy4:
if not GetKeyState("1joy4")  ; The button has been released.
{
    Send {ENTER up}  ; Release the RALT.
    SetTimer, WaitFor1joy4, off  ; Stop monitoring the button.
    return
}
; Since above didn't "return", the button is still being held down.
Send {ENTER down}  ; Send another RALT keystroke.
return

1joy5::
Send {1 down}   ; Press the RALT down.
SetTimer, WaitFor1joy5, 50  ; Reduce the number 30 to 20 or 10 to send keys faster. Increase it to send slower.
return

WaitFor1joy5:
if not GetKeyState("1joy5")  ; The button has been released.
{
    Send {1 up}  ; Release the RALT.
    SetTimer, WaitFor1joy5, off  ; Stop monitoring the button.
    return
}
; Since above didn't "return", the button is still being held down.
Send {1 down}  ; Send another RALT keystroke.
return

1joy9::
Send {ESC down}   ; Press the RALT down.
SetTimer, WaitFor1joy9, 50  ; Reduce the number 30 to 20 or 10 to send keys faster. Increase it to send slower.
return

WaitFor1joy9:
if not GetKeyState("1joy9")  ; The button has been released.
{
    Send {ESC up}  ; Release the RALT.
    SetTimer, WaitFor1joy9, off  ; Stop monitoring the button.
    return
}
; Since above didn't "return", the button is still being held down.
Send {ESC down}  ; Send another RALT keystroke.
return

1joy10::
Send {ENTER down}   ; Press the RALT down.
SetTimer, WaitFor1joy10, 50  ; Reduce the number 30 to 20 or 10 to send keys faster. Increase it to send slower.
return

WaitFor1joy10:
if not GetKeyState("1joy10")  ; The button has been released.
{
    Send {ENTER up}  ; Release the RALT.
    SetTimer, WaitFor1joy10, off  ; Stop monitoring the button.
    return
}
; Since above didn't "return", the button is still being held down.
Send {ENTER down}  ; Send another RALT keystroke.
return
Player 2:

Code: Select all

#Persistent  ; Keep this script running until the user explicitly exits it.
SetTimer, WatchPOV, 5
return

WatchPOV: 
GetKeyState, POV, 2JoyPOV  ; Get position of the POV control. 
Key1ToHoldDownPrev = %Key1ToHoldDown% 
Key2ToHoldDownPrev = %Key2ToHoldDown% 
; Each "Prev" variable now holds the key that was down before (if any). 

; Some joysticks might have a smooth/continous POV rather than one in fixed increments. 
; To support them all, check for ranges: 
if POV < 0   ; No angle to report
{ 
   Key1ToHoldDown = 
} 
else if POV between 35000 and 36000                 ; 337.5 to 360 degrees: Forward 
{ 
   Key1ToHoldDown = W 
} 
else if POV between 0 and 1000      ; 0 to 22.5 degrees: Forward 
{ 
   Key1ToHoldDown = W 
   Key2ToHoldDown = 
} 
else if POV between 1000 and 8000   ; Up+Right 
{ 
   Key1ToHoldDown = E

} 
else if POV between 8000 and 11000  ; Right 
{ 
   Key1ToHoldDown = D
} 
else if POV between 11000 and 17000 ; Down+Right 
{ 
   Key1ToHoldDown = C
} 
else if POV between 17000 and 19000 ; Down 
{ 
   Key1ToHoldDown = X 
} 
else if POV between 19000 and 26000 ; Down+Left 
{ 
   Key1ToHoldDown = Z 
} 
else if POV between 26000 and 28000 ; Left 
{ 
   Key1ToHoldDown = A 
} 
else if POV between 28000 and 35000 ; Up+Left 
{ 
   Key1ToHoldDown = Q
} 

SetKeyDelay -1  ; Avoid delays between keystrokes. 

if Key1ToHoldDown <> %Key1ToHoldDownPrev%  ; Key #1 needs adjusting. 
{ 
   if Key1ToHoldDownPrev <>   ; There is a previous key to release. 
      Send, {%Key1ToHoldDownPrev% up}  ; Release it. 
   if Key1ToHoldDown <>   ; There is a key to press down. 
      Send, {%Key1ToHoldDown% down}  ; Press it down. 
} 
if Key2ToHoldDown <> %Key2ToHoldDownPrev%  ; Key #2 needs adjusting. 
{ 
   if Key2ToHoldDownPrev <>   ; There is a previous key to release. 
      Send, {%Key2ToHoldDownPrev% up}  ; Release it. 
   if Key2ToHoldDown <>   ; There is a key to press down. 
      Send, {%Key2ToHoldDown% down}  ; Press it down. 
} 


WatchAxis:
2JoyX := GetKeyState("2JoyX")  ; Get position of X axis.
2JoyY := GetKeyState("2JoyY")  ; Get position of Y axis.
KeyToHoldDownPrev := KeyToHoldDown  ; Prev now holds the key that was down before (if any).

if (2JoyX > 70 and 2JoyY < 30)
    KeyToHoldDown := "E"
else if (2JoyX > 70 and 2JoyY > 70)
    KeyToHoldDown := "C"
else if (2JoyX < 30 and 2JoyY > 70)
    KeyToHoldDown := "Z"
else if (2JoyX < 30 and 2JoyY < 30)
    KeyToHoldDown := "Q"
else if (2JoyX > 70)
    KeyToHoldDown := "D"
else if (2JoyX < 30)
    KeyToHoldDown := "A"
else if (2JoyY > 70)
    KeyToHoldDown := "X"
else if (2JoyY < 30)
    KeyToHoldDown := "W"
else
    KeyToHoldDown := ""

if (KeyToHoldDown = KeyToHoldDownPrev)  ; The correct key is already down (or no key is needed).
    return  ; Do nothing.

; Otherwise, release the previous key and press down the new key:
SetKeyDelay -1  ; Avoid delays between keystrokes.
if KeyToHoldDownPrev   ; There is a previous key to release.
    Send, {%KeyToHoldDownPrev% up}  ; Release it.
if KeyToHoldDown   ; There is a key to press down.
    Send, {%KeyToHoldDown% down}  ; Press it down.
return





2Joy3::
Send {LSHIFT down}   ; Press the RALT down.
SetTimer, WaitFor2Joy3, 50  ; Reduce the number 30 to 20 or 10 to send keys faster. Increase it to send slower.
return

WaitFor2Joy3:
if not GetKeyState("2Joy3")  ; The button has been released.
{
    Send {LSHIFT up}  ; Release the RALT.
    SetTimer, WaitFor2Joy3, off  ; Stop monitoring the button.
    return
}
; Since above didn't "return", the button is still being held down.
Send {LSHIFT down}  ; Send another RALT keystroke.
return

2Joy4::
Send {TAB down}   ; Press the RALT down.
SetTimer, WaitFor2Joy4, 50  ; Reduce the number 30 to 20 or 10 to send keys faster. Increase it to send slower.
return

WaitFor2Joy4:
if not GetKeyState("2Joy4")  ; The button has been released.
{
    Send {TAB up}  ; Release the RALT.
    SetTimer, WaitFor2Joy4, off  ; Stop monitoring the button.
    return
}
; Since above didn't "return", the button is still being held down.
Send {TAB down}  ; Send another RALT keystroke.
return

2Joy5::
Send {1 down}   ; Press the RALT down.
SetTimer, WaitFor2Joy5, 50  ; Reduce the number 30 to 20 or 10 to send keys faster. Increase it to send slower.
return

WaitFor2Joy5:
if not GetKeyState("2Joy5")  ; The button has been released.
{
    Send {1 up}  ; Release the RALT.
    SetTimer, WaitFor2Joy5, off  ; Stop monitoring the button.
    return
}
; Since above didn't "return", the button is still being held down.
Send {1 down}  ; Send another RALT keystroke.
return

2Joy9::
Send {ESC down}   ; Press the RALT down.
SetTimer, WaitFor2Joy9, 50  ; Reduce the number 30 to 20 or 10 to send keys faster. Increase it to send slower.
return

WaitFor2Joy9:
if not GetKeyState("2Joy9")  ; The button has been released.
{
    Send {ESC up}  ; Release the RALT.
    SetTimer, WaitFor2Joy9, off  ; Stop monitoring the button.
    return
}
; Since above didn't "return", the button is still being held down.
Send {ESC down}  ; Send another RALT keystroke.
return

2Joy10::
Send {ENTER down}   ; Press the RALT down.
SetTimer, WaitFor2Joy10, 50  ; Reduce the number 30 to 20 or 10 to send keys faster. Increase it to send slower.
return

WaitFor2Joy10:
if not GetKeyState("2Joy10")  ; The button has been released.
{
    Send {ENTER up}  ; Release the RALT.
    SetTimer, WaitFor2Joy10, off  ; Stop monitoring the button.
    return
}
; Since above didn't "return", the button is still being held down.
Send {ENTER down}  ; Send another RALT keystroke.
return
Here are some notes which I took along my search for the solution which helped me:
Found in after Google search: autohotkey analog joystick
on Page 2 Result 3

Analog Joystick or Arrow Keys to Mouse Movement? for RE4
https://www.autohotkey.com/board/topic/18801-analog-joystick-or-arrow-keys-to-mouse-movement-for-re4/


Another Great link which helped me figure out the analog controls:

Remapping a Joystick to Keyboard or Mouse
Making Other Joystick Controls Send Keystrokes or Mouse Clicks
https://www.autohotkey.com/docs/misc/RemapJoystick.htm


Another Links that helped me (After Google Search: autohotkey analog axis)

JoyX JoyY to SendInput
https://superuser.com/questions/315499/joyx-joyy-to-sendinput

Stop Analog at Y-axis 75 when button is clicked
viewtopic.php?t=64597


Update 2:
I tried to write a script for Robotron 2084 for the PC DOS for dual analog controls, I thought it would be a nice project:
so here is the script:

Code: Select all

#Persistent  ; Keep this script running until the user explicitly exits it.
SetTimer, WatchPOV, 5
return


WatchPOV: 
GetKeyState, POV, 1JoyPOV  ; Get position of the POV control. 
Key1ToHoldDownPrev = %Key1ToHoldDown% 
Key2ToHoldDownPrev = %Key2ToHoldDown% 
; Each "Prev" variable now holds the key that was down before (if any). 

; Some joysticks might have a smooth/continous POV rather than one in fixed increments. 
; To support them all, check for ranges: 
if POV < 0   ; No angle to report
{ 
   Key1ToHoldDown = 
} 
else if POV between 35000 and 36000                 ; 337.5 to 360 degrees: Forward 
{ 
   Key1ToHoldDown = Numpad8 
} 
else if POV between 0 and 1000      ; 0 to 22.5 degrees: Forward 
{ 
   Key1ToHoldDown = Numpad8 
   Key2ToHoldDown = 
} 
else if POV between 1000 and 8000   ; Up+Right 
{ 
   Key1ToHoldDown = Numpad9

} 
else if POV between 8000 and 11000  ; Right 
{ 
   Key1ToHoldDown = Numpad6
} 
else if POV between 11000 and 17000 ; Down+Right 
{ 
   Key1ToHoldDown = Numpad3
} 
else if POV between 17000 and 19000 ; Down 
{ 
   Key1ToHoldDown = Numpad2 
} 
else if POV between 19000 and 26000 ; Down+Left 
{ 
   Key1ToHoldDown = Numpad1 
} 
else if POV between 26000 and 28000 ; Left 
{ 
   Key1ToHoldDown = Numpad4 
} 
else if POV between 28000 and 35000 ; Up+Left 
{ 
   Key1ToHoldDown = Numpad7
} 

SetKeyDelay -1  ; Avoid delays between keystrokes. 

if Key1ToHoldDown <> %Key1ToHoldDownPrev%  ; Key #1 needs adjusting. 
{ 
   if Key1ToHoldDownPrev <>   ; There is a previous key to release. 
      Send, {%Key1ToHoldDownPrev% up}  ; Release it. 
   if Key1ToHoldDown <>   ; There is a key to press down. 
      Send, {%Key1ToHoldDown% down}  ; Press it down. 
} 
if Key2ToHoldDown <> %Key2ToHoldDownPrev%  ; Key #2 needs adjusting. 
{ 
   if Key2ToHoldDownPrev <>   ; There is a previous key to release. 
      Send, {%Key2ToHoldDownPrev% up}  ; Release it. 
   if Key2ToHoldDown <>   ; There is a key to press down. 
      Send, {%Key2ToHoldDown% down}  ; Press it down. 
} 


WatchAxis:
1JoyX := GetKeyState("1JoyX")  ; Get position of X axis.
1JoyY := GetKeyState("1JoyY")  ; Get position of Y axis.
1JoyR := GetKeyState("1JoyR")  ; Get position of X axis.
1JoyZ := GetKeyState("1JoyZ")  ; Get position of Y axis.
KeyToHoldDownPrev := KeyToHoldDown  ; Prev now holds the key that was down before (if any).

if (1JoyX > 70 and 1JoyY < 30)
    KeyToHoldDown := "NUMPAD9"
else if (1JoyX > 70 and 1JoyY > 70)
    KeyToHoldDown := "NUMPAD3"
else if (1JoyX < 30 and 1JoyY > 70)
    KeyToHoldDown := "NUMPAD1"
else if (1JoyX < 30 and 1JoyY < 30)
    KeyToHoldDown := "NUMPAD7"
else if (1JoyX > 70)
    KeyToHoldDown := "NUMPAD6"
else if (1JoyX < 30)
    KeyToHoldDown := "NUMPAD4"
else if (1JoyY > 70)
    KeyToHoldDown := "NUMPAD2"
else if (1JoyY < 30)
    KeyToHoldDown := "NUMPAD8"

else if (1JoyR > 70 and 1JoyZ < 30)
    KeyToHoldDown := "Z"
else if (1JoyR > 70 and 1JoyZ > 70)
    KeyToHoldDown := "C"
else if (1JoyR < 30 and 1JoyZ > 70)
    KeyToHoldDown := "E"
else if (1JoyR < 30 and 1JoyZ < 30)
    KeyToHoldDown := "Q"
else if (1JoyR > 70)
    KeyToHoldDown := "X"
else if (1JoyR < 30)
    KeyToHoldDown := "W"
else if (1JoyZ > 70)
    KeyToHoldDown := "D"
else if (1JoyZ < 30)
    KeyToHoldDown := "A"
else
    KeyToHoldDown := ""

if (KeyToHoldDown = KeyToHoldDownPrev)  ; The correct key is already down (or no key is needed).
    return  ; Do nothing.

; Otherwise, release the previous key and press down the new key:
SetKeyDelay -1  ; Avoid delays between keystrokes.
if KeyToHoldDownPrev   ; There is a previous key to release.
    Send, {%KeyToHoldDownPrev% up}  ; Release it.
if KeyToHoldDown   ; There is a key to press down.
    Send, {%KeyToHoldDown% down}  ; Press it down.
return





1joy3::
Send {NUMPAD5 down}   ; Press the RALT down.
SetTimer, WaitFor1joy3, 50  ; Reduce the number 30 to 20 or 10 to send keys faster. Increase it to send slower.
return

WaitFor1joy3:
if not GetKeyState("1joy3")  ; The button has been released.
{
    Send {NUMPAD5 up}  ; Release the RALT.
    SetTimer, WaitFor1joy3, off  ; Stop monitoring the button.
    return
}
; Since above didn't "return", the button is still being held down.
Send {NUMPAD5 down}  ; Send another RALT keystroke.
return

1joy4::
Send {NUMPAD5 down}   ; Press the RALT down.
SetTimer, WaitFor1joy4, 50  ; Reduce the number 30 to 20 or 10 to send keys faster. Increase it to send slower.
return

WaitFor1joy4:
if not GetKeyState("1joy4")  ; The button has been released.
{
    Send {NUMPAD5up}  ; Release the RALT.
    SetTimer, WaitFor1joy4, off  ; Stop monitoring the button.
    return
}
; Since above didn't "return", the button is still being held down.
Send {NUMPAD5 down}  ; Send another RALT keystroke.
return

1joy5::
Send {1 down}   ; Press the RALT down.
SetTimer, WaitFor1joy5, 50  ; Reduce the number 30 to 20 or 10 to send keys faster. Increase it to send slower.
return

WaitFor1joy5:
if not GetKeyState("1joy5")  ; The button has been released.
{
    Send {1 up}  ; Release the RALT.
    SetTimer, WaitFor1joy5, off  ; Stop monitoring the button.
    return
}
; Since above didn't "return", the button is still being held down.
Send {1 down}  ; Send another RALT keystroke.
return

1joy9::
Send {ESC down}   ; Press the RALT down.
SetTimer, WaitFor1joy9, 50  ; Reduce the number 30 to 20 or 10 to send keys faster. Increase it to send slower.
return

WaitFor1joy9:
if not GetKeyState("1joy9")  ; The button has been released.
{
    Send {ESC up}  ; Release the RALT.
    SetTimer, WaitFor1joy9, off  ; Stop monitoring the button.
    return
}
; Since above didn't "return", the button is still being held down.
Send {ESC down}  ; Send another RALT keystroke.
return

1joy10::
Send {ENTER down}   ; Press the RALT down.
SetTimer, WaitFor1joy10, 50  ; Reduce the number 30 to 20 or 10 to send keys faster. Increase it to send slower.
return

WaitFor1joy10:
if not GetKeyState("1joy10")  ; The button has been released.
{
    Send {ENTER up}  ; Release the RALT.
    SetTimer, WaitFor1joy10, off  ; Stop monitoring the button.
    return
}
; Since above didn't "return", the button is still being held down.
Send {ENTER down}  ; Send another RALT keystroke.
return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: GooGooPark and 128 guests