Requesting help for setting 1 key to perform as if 2 keys are being held down.

Ask gaming related questions (AHK v1.1 and older)
Jza
Posts: 28
Joined: 11 Mar 2020, 22:54

Requesting help for setting 1 key to perform as if 2 keys are being held down.

11 Mar 2020, 23:09

Hello. I am new to AHK (well I've used it many years ago and am new again!). Here is the functionality I am trying to achieve.

I would like the Right Shift key to act as if I am pressing down the Right Shift key AND another key. For example the forward slash key "/". And then when I release the Right Shift key, it is as if Right Shift and / have been released. This is for a new Steam game I've recently purchased that has a functionality that is too complicated compared to what I'd like.

So I use my Right Shift key as an aim down the sight button. Once you are aiming down the sight, you can again hit another key to activate the ZOOM. In older games, aiming down the sight automatically applied the zoomed view for you. In this game, it doesn't. I'd like it to act like games from my younger days. Remember you can only zoom AFTER you have aimed down the sight. So for example I would do this:

RightShift (to aim down the sight) then press another key to ZOOM, "/" or forward slash in this case. I hold these down, I do not toggle them. How can I make both of these things happen just by holding down the RightShift key by itself?

RightShift held down = Right shift and "/" held down. (/ might have to come into play a millisecond or so after RightShift if I find they don't work simultaneously because of reasons explained above; can only zoom after aim down the sight has been initiated.

RightShift NOT held down = RightShift and "/" released.

Sorry for rambling I feel if I explain it multiple ways, more people with good knowledge of AHK may be able to help me. Thanks for reading.
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Requesting help for setting 1 key to perform as if 2 keys are being held down.

11 Mar 2020, 23:26

Try:

Code: Select all

SetKeyDelay, 50, 50
~RShift::Send,{/ Down}
~RShift Up::Send, {/ Up}
Jza
Posts: 28
Joined: 11 Mar 2020, 22:54

Re: Requesting help for setting 1 key to perform as if 2 keys are being held down.

12 Mar 2020, 09:24

Thanks for the suggestion, that code yields the same results of my own testing where when I hold Rshift down, it continuously spams my character in and out of the state of aiming down the sight in rapid fashion.

EDIT: Just tried this based on your post, results a little better, but still not desired effect:

Code: Select all

SetKeyDelay, 50, 50
~RShift::Send,{Rshift Down} {/ Down}
~RShift Up::Send, {Rshift Up} {/ Up}
I'm new to AHK so I need to learn and understand the syntax to get to where I want. Baby steps.

Edit 2: And this is working even better, just still not perfect:

Code: Select all

#InputLevel 1
~Rshift::Send, {Rshift Down} {/ Down}
~RShift Up::Send, {Rshift Up} {/ Up}
Return
#InputLevel 0
Unsure of what each thing does as it's freshly researched. Unsure of best way to have the smallest delay before / is pressed AFTER Rshift.

Edit 3: Getting closer, this has desired effect, except for when I let go of the RShift key, my character briefly aims down the sight again for a second before returning to a normal state. Not sure why this is happening looking at the AHK code... Simplified code is better.

Code: Select all

~Rshift::Send, {Rshift Down} {/ Down}
~RShift Up::Send, {Rshift Up} {/ Up}
Edit 4: With the following code I get the desired effect. Only issue is, the longer I hold down the shift key, the longer it takes to return to a normal state after I release it. I guess it has something to do with when I hold down Rshift a key input is being spammed and by holding it down long there is a backlog of input going to the system? I removed the "~". I don't know what the tildas do.

Code: Select all

Rshift::Send, {Rshift Down} {/ Down}
RShift Up::Send, {Rshift Up} {/ Up}
Jza
Posts: 28
Joined: 11 Mar 2020, 22:54

Re: Requesting help for setting 1 key to perform as if 2 keys are being held down.

12 Mar 2020, 12:05

Also thank you Xtra for giving me something to start with.

Code: Select all

SetKeyDelay, 0
Rshift::Send, {Rshift Down} {/ Down}
RShift Up::Send, {Rshift Up} {/ Up}
OK the code above seems to work pretty much how I wanted it to. Adding SetKeyDelay, 0 solved the issue of my character taking an extra second to return back to normal. The only issue I am having now is sometimes the ZOOM or / key in my case will not take and it will only aim down the sight (Rshift). When I am using the sprint key the ZOOM never works when I hit Rshift, but if I hit it again while still holding my sprint key, it works every time. Unsure why.

What would be the best way to have the / key get pressed down about 5 or 10 milliseconds after the Rshift key?

Would something like this work?

Code: Select all

SetKeyDelay, 0
Rshift::Send, {Rshift Down}
SetKeyDelay, 5
Rshift::Send, {/ Down}
RShift Up::Send, {Rshift Up} {/ Up}
Welps, that didn't work. So this works wonderfully, just don't know why it only works the SECOND time it is pressed when using a sprint key with the following:

Code: Select all

SetKeyDelay, 0
Rshift::Send, {Rshift Down} {/ Down}
RShift Up::Send, {Rshift Up} {/ Up}
Any tips insight or thoughts wanted. Thanks AHK community.
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Requesting help for setting 1 key to perform as if 2 keys are being held down.

12 Mar 2020, 12:46

Setting the delay to 0 is the same as using SendInput.
Note: having a space between the {Rshift Down} {/ Down} is sending the spacebar also.
Try:

Code: Select all

Rshift::
    SendInput, {Rshift Down}
    Sleep 50    ; Increase to 100 if still having issues.
    SendInput, {/ Down}
return

RShift Up::SendInput, {Rshift Up}{/ Up}
The sleep will give brief delay between the 2 actions
Jza
Posts: 28
Joined: 11 Mar 2020, 22:54

Re: Requesting help for setting 1 key to perform as if 2 keys are being held down.

12 Mar 2020, 12:55

Thank you, I will try this. I was looking into using the KeyWait thing, but obviously I was not using it correctly.
Jza
Posts: 28
Joined: 11 Mar 2020, 22:54

Re: Requesting help for setting 1 key to perform as if 2 keys are being held down.

12 Mar 2020, 13:06

OK tried that code, oddly the zoom function or / almost never worked regardless of increasing the sleep time. But if I double clicked Rshift and held it down it worked every time, EVEN while holding the sprint key. So one thing fixed but another arisen. Thanks again for trying to help Xtra! I assume you are a regular around here.

EDIT - I just noticed what you said about the space bar and noticed that in notepad testing, thank you for telling me that!
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Requesting help for setting 1 key to perform as if 2 keys are being held down.

12 Mar 2020, 13:19

Ok to get a double click try:

Code: Select all

~Rshift::
    SendInput, {Rshift Down}
    Sleep 50    ; Increase to 100 if still having issues.
    SendInput, {/ Down}
return

RShift Up::SendInput, {Rshift Up}{/ Up}
Jza
Posts: 28
Joined: 11 Mar 2020, 22:54

Re: Requesting help for setting 1 key to perform as if 2 keys are being held down.

12 Mar 2020, 13:20

I noticed in notepad testing, hitting Rshift by tapping over and over produces this:

??????????????????????????????? - looks like desired effect, when I HOLD down the right shift for a few seconds and suddenly release, it usually produces this:

????????????????????????????????/???????????????????????????????????????????????/?????????????????????/??????????????????????????????????????/??????????????/

Abour 75% of the time it finishes with a /. So it appears AHK thinks / is still held down at times that Rshift is not being held down. Hope this helps you help me.
Jza
Posts: 28
Joined: 11 Mar 2020, 22:54

Re: Requesting help for setting 1 key to perform as if 2 keys are being held down.

12 Mar 2020, 13:23

I tried your last code adding the ~, it made my character spaz out. In notepad Rshift produces solely //////////////////////////////////////////////.

Wish I could understand the KeyWait function, appears to be what I need. https://www.autohotkey.com/docs/commands/KeyWait.htm
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Requesting help for setting 1 key to perform as if 2 keys are being held down.

12 Mar 2020, 13:26

This is what im seeing:////////////////////////////////////////////////////////////////
You could try it this way:

Code: Select all

Rshift::
    SendInput, {Rshift}{Rshift Down}
    Sleep 50    ; Increase to 100 if still having issues.
    SendInput, {/ Down}
return

RShift Up::SendInput, {Rshift Up}{/ Up}
Jza
Posts: 28
Joined: 11 Mar 2020, 22:54

Re: Requesting help for setting 1 key to perform as if 2 keys are being held down.

12 Mar 2020, 14:28

I tried that, and I am back to this:

Code: Select all

SetKeyDelay, 0
Rshift::Send, {Rshift Down}{/ Down}
RShift Up::Send, {/ Up}{Rshift Up}
That seems like the closest I can get working. It works 90% of the time (never if using my sprint key). I appreciate all of your help and I think you've done enough. I need to try to figure out what is keeping it from working 100%. The game isn't a well known game either, it's called Post Scriptum and it is a World War 2 simulator of sorts. Maybe in a future patch they can make this easier for me to accomplish. I'll try some more stuff and I really appreciate your assistance Xtra.
Jza
Posts: 28
Joined: 11 Mar 2020, 22:54

Re: Requesting help for setting 1 key to perform as if 2 keys are being held down.

12 Mar 2020, 14:32

Notepad is quite the teacher btw.... my sprint key was 4, shift makes it $$$. I'm really dumb for not realizing that earlier... sigh.. maybe there is light at the end of the tunnel.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 34 guests