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
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