Grab escape script Topic is solved

Ask gaming related questions (AHK v1.1 and older)
Raiden96
Posts: 38
Joined: 23 Oct 2021, 07:03

Grab escape script

Post by Raiden96 » 24 Oct 2021, 13:37

I'm trying to make a script for a game that allows me to break free from an enemy grab by pressing A D when prompted. I.e the script is supposed to press A then D then A then again D while holding LAlt then stop doing all that after releasing LAlt with a short delay between each keystroke. It should simulate how a human would tap A then D with a short delay between keystrokes. This is what i have tried but no dice. I'm a beginner so my apologize for the dumb question.

Code: Select all

While GetKeyState("LAlt", "P")
	Send {A up}
	SetKeyDelay 50
	Send {D up}
	SetKeyDelay 50
	Send {A down}
	SetKeyDelay 50
	Send {D down}
	SetKeyDelay 50
If there are things still unclear about what i'm trying to do please point it out. I'll try to clarify as best as i can.
Thanks in advance!

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

Re: Grab escape script

Post by mikeyww » 24 Oct 2021, 13:57

While would use braces around a block of code, or else it would apply only to the single statement that follows it.

Code: Select all

LAlt::
SetKeyDelay, 50
While GetKeyState(A_ThisHotkey, "P")
 Send ad
Return
Explained: Blocks

SetKeyDelay is not synonymous with Sleep. It can be specified once for a thread like yours.

Raiden96
Posts: 38
Joined: 23 Oct 2021, 07:03

Re: Grab escape script

Post by Raiden96 » 25 Oct 2021, 04:57

Thanks @mikeyww!

Code: Select all

LAlt::
SetKeyDelay, 50
While GetKeyState(A_ThisHotkey, "P")
{
 Send AD
}
Return
I've tried it and it doesn't work. I checked a similar post where someone tried to do what i'm trying to do and someone pointed out the following :
You just need to separate the keypresses into separate up/down events. The simple reason for this is that AHK can press and release a key so quickly that the game will not register it.

A couple side notes:

1. Typically AHK scripts must be run 'as administrator' to interact with games. (Right click on script, run as administrator)

2. AHK has difficulty registering keystrokes in full screen games. You might have to run the game in windowed mode.
I don't think running the script as an administrator is gonna fix this, since i already tried it. Also, running the game in window mode didn't help fix the issue either.
The odd thing is that the script performs well in notepad inputting the A and D keys as expected with the set delay.

I'm thinking that
You just need to separate the keypresses into separate up/down events. The simple reason for this is that AHK can press and release a key so quickly that the game will not register it.
this might fix the issue i'm having. But i'll be honest, i don't know how to achieve this. I don't understand how to separate the keypresses into separate up/down events . I tried using up/down for keypresses but it didn't work. Most likely because i didn't use them correctly

Could you help me get to the bottom of this? I'm trying to learn as much as possible, but there's only so much i can do on my own. Thanks!

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

Re: Grab escape script  Topic is solved

Post by mikeyww » 25 Oct 2021, 05:56

Since your script works in Notepad, the problem is not the script. It is how your target window responds to the script. You can adjust the press duration as follows.

Code: Select all

LAlt::
SetKeyDelay, 50, 50
While GetKeyState(A_ThisHotkey, "P")
 Send ad
Return
I suggest using lower-case letters if they work in your game. Test in Notepad first. You can also try tips for games. https://autohotkey.com/board/topic/111737-how-to-make-ahk-work-in-most-games-the-basics/

Raiden96
Posts: 38
Joined: 23 Oct 2021, 07:03

Re: Grab escape script

Post by Raiden96 » 27 Oct 2021, 05:20

Thanks @mikeyww for your help! I've managed to make it work and build more scripts similar to this one. Your help has been invaluable.

Post Reply

Return to “Gaming Help (v1)”