Help with code for Muscular Dystrophy user!

Need Help

Hello!

Not long ago I started playing an online racing game where I have met countless people and interacted with many on friendlier terms and I came across this one person loves the game, however his condition is making it very difficult to play on keyboard.

This person uses Switch joycon controllers that are remapped through the reWASD application basically mirroring keyboard inputs when used.

In the game, you are able to perform a drift by pressing the Shift button and then choosing to whether Drift to the right or left with either the arrow buttons or a or d buttons. After a drift has been performed, if you press Shift again and the upwards button, you get a small boost. I use keyboard myself and I thought since the reWASD application mirrors anything, maybe I can set something up for the guy?

I created the following code,

Shift::

{ keywait, Shift Sleep, 500 send, Shift } return

Since this person has difficulties pressing multiple buttons at the same time, the above code saves him at least one button click each drift. So when he shifts and performs the drift, the boosting option becomes available within half a second (that's the reason for the delay) so all he should really need to do after a successful drift is to press the upwards button since shift will be repeating itself and thus saving him one click.

What I noticed is that whe nusing the joycon controllers, when driving the code resets? Suddenly the shift button is not performing a secondary action, since there are other inputs such as the joycon WASD controllers being moved.

I believe the solution to this is that a code should have in mind that when W, A, S, D or Shift is pressed together and then released it should repeat the Shift buton after 500ms so that all he needs to do is to press the Upwards button, or W, to perform the drift boost.

I am very new to AHK and I have really tried getting into it, and assist this person since he really loves the game and I'd like him to keep playing instead of giving it up because of his condition so I want to ask help from the community.

Is there anyone willing with knowledge on how we could solve this matter?

Thank you so much in advance.

Ps.

Shift::

{ keywait, Shift keywait, w keywait, d keywait, s keywait, a Sleep, 500 send, Shift } return

The above is another code I tried but I feel like that's totally wrong. I can't seem to find how to combine a keywait with multiple inputs.

Posted May 23, 2020, 8:01 PM UTC

416
davebrny•

this is the first time ive heard of reWASD. thats a nice looking GUI

ill have a better look into this tomorrow but off the top of my head, i think you might be able to do it by focusing on mapping the up key instead of the shift key.

for example: when "up" is pressed, check what the previous hotkey was (A_PriorHotkey). if it was one of the drifting hotkey combinations, then send shift+up, else just send regular up.

the variables A_TimeSinceThisHotkey and A_TimeSincePriorHotkey could be used as well and make it so shift+up is only sent if the time between those two variables is under 500 ms

2
Crs_RodOP•

Hello, thank you for your comment! I appreciate the input and will have a look into those variables :D

1
joesii•

when using the joycon controllers, when driving the code resets? Suddenly the shift button is not performing a secondary action, since there are other inputs such as the joycon WASD controllers being moved.

I don't understand what you mean.

Also I've personally never been in a situation where I found keywait to be useful; even though I don't know what your problem is, I would imagine it might be a problem.

Anyway, that aside, I also am not sure if I even understand the drift mechanic. Does the the boost work mid-drift, or does using the boost end the drift? (like in Mario Kart). By "the boosting becomes available in half a second", you mean that is the minimum time required to do a drift, and that you can do multiple in a row of let's say 500-600ms each? Are there cases where one might want to do a single longer sustained drift, such as performing a 180° or even >180° turn instead of always doing the minimum 500 ms?

I suppose regardless of the answer a solution might be to automate the entire drift sequence to a specific key or key combination (an entirely separate key would probably be hard to work on a Switch I imagine). So if you always wanted a 500 ms fixed drift (the easier option, but having the drift hold while you hold down a key combination can also be done, just a bit more advanced to code) you could do this:

 ;(this is only code for the left drift)
+a::
send {shift down}{a down}
sleep 520
send {a up}{shift up}
sleep 50
send {shift down}{w down}
sleep 50
send {w up}{shift up}
return   

I feel like you may not given enough details on what you need and/or how boosting/drifting in the game not only works but how it is used, but that is preliminary code as to what I think could be done to automate everything to a "single" keypress.

If you want the drift to be of a variable duration that lasts as long as the key is held down (and just automatically add the boost at the end) that can be done too.

1
davebrny•

you could save a few lines here by adding UP to the hotkey and it would only activate when the hotkey is released

+a UP::

also using passthrough mode would mean you wouldnt have to worry about sending shift+a at all

~+a UP::
sleep 500
send +{w}

cc u/Crs_Rod

2
Crs_RodOP•

Hello, thank you once again for the help. I have put both a and d triggers in and it seems to work as intended for me, I am awaiting a response from him with the joy controllers and if they will do what it does on keyboard for him :D Thanks!

2
joesii•

Also let us know if they can think of any other usability conveniences that will help them with computers. I think a lot of people —or at least me— like to help people with disabilities when possible.

2
Crs_RodOP•

Will do!

1
Crs_RodOP•

This seems to work really well! The timing is off but that's something we can test and come forward to a solution to, thank you very much for the assistance :)

1
Crs_RodOP•

Thank you so much, I will have a look into this!

1
Crs_RodOP•

Hello. Thank you for your comment, I might of not been as clear as I should of been so let me give it another shot.

The boosting can only be done after the drift has been performed, so there can be no boosting mid drift. Whether I hold the shift key for one second to perform a small drift, or as you mentioned above, if I hold the shift for three seconds for a longer drift, the boost can only be done when the shift button has been released.

For more visual explanation, drift 2 till 4 are the ones Im trying to work on and they are displayed in the following video where I have time stamped it to go directly to the showcase of the drift styles. https://youtu.be/TBrMdDSz4d0?t=109

It's that after a drift, you have around 500 ms to press shift and upwards since that is how long the option is available.

I will try with the example you've given me above, and I really hope I am able to assist the guy with a solution so he doesn't need to give up the game :) Thanks!

1
davebrny•
#noEnv
#singleInstance force
sendMode, input
#installKeybdHook
return  ; end of auto-execute


~+d::return    
~+a::return


$w::    
elapsed_time := a_timeSincePriorHotkey - a_timeSinceThisHotkey
if (a_priorHotkey = "~+a") or (a_priorHotkey = "~+d") and (elapsed_time < 500)
    msgbox % a_priorHotkey "`n" elapsed_time
    ; send +{w}
else send {w}
return

give this a go. it should only show the message box if the last hotkey was shift+a or shift+d and if it happened less that 500ms ago

.

shift+a and shift+d are set as hotkeys but using ~ passthrough mode so they should continue to work as normal

#installKeybdHook has to be added to the auto-execute section of your script for the a_priorHotkey variable to pick up +a and +d. it would just detect single key presses otherwise

$ is used in front of "w" so that the code isnt triggered again when the send {w} command is being executed

1
Crs_RodOP•

Hi thank you so much for the Code.

I've given it a go and unfortunately it is not working, and the passthrough mode is unforunately not allowing a normal W to be pressed while the script is active however as long as the code works using the upwards button will do as good. However nothing seems to be happening. I dont get any popup windows nor do I see any inputs when I have the on screen keyboard at the side just to see if the shift button activates as it does with my first code I wrote above.

The variables you've been using are way over the skill level I am currently at so I will try to see if I can make it work. Thanks again!

1
davebrny•

hmm, something else might be interfering with it because the pass through mode on the other hotkeys shouldnt be effecting the W key, i dont think anyway

you could try suspending another other scripts that might be conflicting, or maybe try turning off reWASD so you pinpoint where the problem is happening

1
Crs_RodOP•

Thanks for your reply! With the Joycon controllers, drifting is a known problem where the keys just press on their own which can make extra inputs unkowingly messing things up for me. Also disabling reWASD would disable the inputs being made from the joycon controller to the game itself since that's where the keys are mapped to the keyboard :(

I am going to see if we can find another solution perhaps, maybe a much smaller keyboard that only has the left side which might make it easier to place and use. Thanks again for your attempt to help <3

1
davebrny•

oh i just meant disable it temporarily so you could get the autohotkey code working the way you want with a normal keyboard and then add reWASD back into the mix. theres just probably a lot of places where things could be going wrong and its hard to know where!

1