After days of Internet research and manifold experimentation I have come up with a big fat zero. Perhaps this is because it is not possible. I am not lazy and I have been a coder for a career. But, for the life of me I don't know what else to do. Further, while I was a pretty fair coder in my day, these days I have a very difficult time with multi-matrix structures and get confused very easily. I have been working on the below script for three days. Hence, my reason for finally revealing my ignorance to this forum. Enough of the disclaimer, but I am grateful for your patience.
The script code below contains the rationale in the initial commentary. I hope this makes sense? So, why doesn't it work? I have tried to offer a context in the comments, but I will be happy to expound or clarify on anything.
Thank you.
Code: Select all
/*
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
LOCOMOTIVE CAB CONTROLS FOR RXR ENGINEERS
=========================================
The intent of this script is to "catch" axis movement for the purposes of creating a train locomotive control panel which normally consistes of the following...
-- Throttle Lever - it makes the train go.
-- Reverser - directs the train to go forward or backwars as well as making the best use of steam output from steam locomotives.
-- Brake Lever - Makes the train slow and stop.
-- Dynamic Brake Lever - a "running" brake which uses the electomagnetic force of the wheel's motors to create electro-resistance against the direction of wheel spin.
This script is a modification of the "Remapping" script.
Simply, the script polls the controller axes continuously approx. every 500 milliseconds or thereabouts (this should be user-adjustable).
There are 1 of 6 actions triggered every time a lever is moved. ..
-- Pushing the 1st lever forward enters... "W" key press and release (Reverser increase).
-- Pull the 1st lever rearward enters..... "S" key press and release (Reverser decrease).
-- Pushing the 2nd lever forward enters... "A" key press and release (Throttle decrease). ***Note: the 2nd Lever increase/decrease is opposite Lever 1 and Lever 3.
-- Pull the 2nd lever forward enters...... "D" key press and release.
-- Pushing the 3rd lever forward enters... "'" (apostrophe) key press and release.
-- Pull the 3rd lever forward enters...... ";" (semicolon) key press and release.
Effectively, this means as the levers are continuously moved the intended key is continuously pressed (but not held down).
Logic (as I understand?)
-----------------------
[I will use Lever 2 (Thrttle) as example.
Loop
Read controller axis value, "Joy2"
Move value of "Joy" into variable, "Joy2_Old"
If Joy2 > Joy2_Old then ; Poll for change.
Press and release "A" key ; Decrease Throttle.
Elseif Joy2 = Joy2_Old then ; No movement.
Exit
If Joy2 < Joy2_Old then ; Poll for change.
Press and release "D" key ; Increae Throttle.
End Loop
For simplicity, I am only using one lever in this script. Once I get one lever working, I'm sure I can get the other two working as well (I hope?).
I have tried what you see below, but it doesn't work. Please help.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
*/
#Persistent ; Keep this script running until the user explicitly exits it.
SetTimer, WatchAxis, 5
return
WatchAxis:
; Lever 2 - Throttle
Joy2X := GetKeyState("Joy2X") ; Get position of 2X axis.
Joy2Y := GetKeyState("Joy2Y") ; Get position of 2Y axis.
Joy2X_Old := Joy2X
Joy2Y_Old := Joy2Y
KeyToHoldDownPrev := KeyToHoldDown ; Prev now holds the key that was down before (if any).
if (Joy2X > Joy2X_Old)
KeyToHoldDown := "A"
else if (Joy2X < Joy2X_Old)
KeyToHoldDown := "D"
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