Pressing two keys simultaneously on the first frame

Ask gaming related questions (AHK v1.1 and older)
eexe
Posts: 2
Joined: 14 Jul 2022, 23:11

Pressing two keys simultaneously on the first frame

Post by eexe » 14 Jul 2022, 23:33

Hello, I play a game where I need to press the buttons K, U and J together but I can't do it on my keyboard due to ghosting. So I wanted to write a script that would press U and J simultaneously on the first frame when I press Y since I can press K and Y together. This is what I've written.

Code: Select all

y::
Send, {u down}{j down}{j up}{u up}
return
The problem with this is that I get the U input on the first frame and get U and J together on the second frame which doesn't work for me because the game performs the U action immediately and then can't perform the U J action.

Is there a way to get the U and J input together on the very first frame after I press Y?

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Pressing two keys simultaneously on the first frame

Post by mikeyww » 15 Jul 2022, 06:02

I read this a few times but have no clue what a frame is. AHK knows even less. Imagine you are explaining this to a new user, especially a remote new user who cannot see what you see. How would you explain it in terms of what mouse or keyboard should do?

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Pressing two keys simultaneously on the first frame

Post by swagfag » 15 Jul 2022, 06:29

if thats all u got in ur script, its being affected by the default send delays. ull have to play around with the delay values(and possibly SendModes) until u find a combination that works
SetKeyDelay

make sure to read(and understand) the disclaimers in the remarks, cuz u might come across some pitfalls

eexe
Posts: 2
Joined: 14 Jul 2022, 23:11

Re: Pressing two keys simultaneously on the first frame

Post by eexe » 15 Jul 2022, 08:47

mikeyww wrote:
15 Jul 2022, 06:02
I read this a few times but have no clue what a frame is. AHK knows even less. Imagine you are explaining this to a new user, especially a remote new user who cannot see what you see. How would you explain it in terms of what mouse or keyboard should do?
I'm sorry for not clarifying. The game I mentioned is locked at 60 frames per second which means it updates information on the screen at every ~16ms and I play it using only the keyboard. The game also reads and processes inputs from the keyboard on a per frame basis. For example, if I press the button U the game will perform an action that will last for 12 frames i.e. ~200ms. During the time this action is being performed the game will ignore any additional inputs until the action is completed.

U performs action x, J performs action y and U+J together perform action z. But to perform action z the game needs you to press U+J on the same frame i.e. within a window of ~17ms. If I press U and miss the frame ( a ~16ms window) to press J and instead press J on the very next frame the game performs action x and ignores the U+J input until action x is completed.

So basically, I need the delay between {u down} and {j down} to be at least less than 16ms so that the game recognizes the U+J action. In what I have currently the delay is high enough (more than 16ms but less than 33ms) that the game reads the U input on one frame and U+J input on the next frame and hence performs the U key action ignoring the U+J action.

shanshans
Posts: 27
Joined: 13 Dec 2015, 08:10

Re: Pressing two keys simultaneously on the first frame

Post by shanshans » 15 Jul 2022, 10:33

eexe wrote:
15 Jul 2022, 08:47
mikeyww wrote:
15 Jul 2022, 06:02
I read this a few times but have no clue what a frame is. AHK knows even less. Imagine you are explaining this to a new user, especially a remote new user who cannot see what you see. How would you explain it in terms of what mouse or keyboard should do?
I'm sorry for not clarifying. The game I mentioned is locked at 60 frames per second which means it updates information on the screen at every ~16ms and I play it using only the keyboard. The game also reads and processes inputs from the keyboard on a per frame basis. For example, if I press the button U the game will perform an action that will last for 12 frames i.e. ~200ms. During the time this action is being performed the game will ignore any additional inputs until the action is completed.

U performs action x, J performs action y and U+J together perform action z. But to perform action z the game needs you to press U+J on the same frame i.e. within a window of ~17ms. If I press U and miss the frame ( a ~16ms window) to press J and instead press J on the very next frame the game performs action x and ignores the U+J input until action x is completed.

So basically, I need the delay between {u down} and {j down} to be at least less than 16ms so that the game recognizes the U+J action. In what I have currently the delay is high enough (more than 16ms but less than 33ms) that the game reads the U input on one frame and U+J input on the next frame and hence performs the U key action ignoring the U+J action.


I don't know which is wrong here , but normally with a control method like this the game engine will delay the key output itself(16-25ms) in order to wait for the other key to be pressed.
If the game triggers the key instantly , i doubt the press together mechanic don't even exist...

anyway...
i will try this first

Code: Select all

y::
Send, {u down}{j down}
sleep 10
{j up}{u up}
return
or maybe

Code: Select all

y::
Send, {u down}
sleep 10
{j down}
sleep 10
{j up}{u up}
return

or rewrite it as

Code: Select all

y::
Send, {u down}{j down}
return

y up::
Send, {u up}{j up}
return
[Mod edit: [code][/code] tags added.]

Post Reply

Return to “Gaming Help (v1)”