Need to improve my script pls help Topic is solved

Ask gaming related questions (AHK v1.1 and older)
HH_Comando
Posts: 6
Joined: 19 Jul 2022, 12:29

Need to improve my script pls help

Post by HH_Comando » 19 Jul 2022, 12:50

So i have a script that automatically hit "W" or "S" whenever i release "D" key or "A" key. Here it is:

Code: Select all

~d::
Keywait,d
Send,w
Return

~a::
Keywait,a
Send,s
Return
I have two problems here.

First, this script is not working when im ingame holding right mouseclick button (aim) for some reason. When im not aiming it works fine.

My second problem is i dont want this script to work while im holding down "W" key (moving forward), is that possible? So it will only work while im pressing D or A without W being pressed.

Third can i control how fast W/S will be pressed after i release D/A key? It seems pretty fast but i dont know if i can make it faster by controling this number.

Fourth, can i control for how long this W/S will be pressed/released when i release D/A ?

Fifth i need this to work only on game window

Thanks.

This is my first time making an AHK script, i have experience with other kind of languages but im really lost on AHK, usually i would study and seek for a solution myself instead of asking for the end product, but i dont have the time right now for a new script engine and this is all need. Also i will be able to study and learn from this.

For u wondering why i need such a script, its because when u press W or S after moving sideways (A and D) u break inertia in this specific game im playing so u can turn sideways changing directions much faster.

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

Re: Need to improve my script pls help

Post by mikeyww » 19 Jul 2022, 19:22

Welcome to this AutoHotkey forum!

Examine your :arrow: KeyHistory. It will show you what is happening with the keys.

Code: Select all

winTitle = ahk_exe notepad.exe
#If WinActive(winTitle) && !GetKeyState("w", "P")
~d Up::Send w
~a Up::Send s
#If
See :arrow: SetKeyDelay & SetBatchLines.

You can click on the posted commands & functions to learn more about them.

HH_Comando
Posts: 6
Joined: 19 Jul 2022, 12:29

Re: Need to improve my script pls help

Post by HH_Comando » 20 Jul 2022, 14:07

mikeyww wrote:
19 Jul 2022, 19:22
Welcome to this AutoHotkey forum!

Examine your :arrow: KeyHistory. It will show you what is happening with the keys.

Code: Select all

winTitle = ahk_exe notepad.exe
#If WinActive(winTitle) && !GetKeyState("w", "P")
~d Up::Send w
~a Up::Send s
#If
See :arrow: SetKeyDelay & SetBatchLines.

You can click on the posted commands & functions to learn more about them.
Thanks bro i manage to do a lot of improvements from this.

Im having one problem tho, when capslock is ON it keeps hitting the capslock key. That key change my fire mode ingame at is correlated with a norecoil script i have with capslock modifier.

So i cant just ignore the fact that it keeps hitting capslock and swithing my fire mode everytime i hit a key with capslock ON.

Can u help me with this?

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

Re: Need to improve my script pls help

Post by mikeyww » 20 Jul 2022, 18:44

Have you examined the key history to see what is happening?

If you direct AHK to send a lowercase W, then that is what it will do. The other way:

Code: Select all

~d Up::Send {Blind}w
See https://www.autohotkey.com/docs/commands/Send.htm#blind

Test in Notepad.

HH_Comando
Posts: 6
Joined: 19 Jul 2022, 12:29

Re: Need to improve my script pls help

Post by HH_Comando » 23 Jul 2022, 09:25

mikeyww wrote:
20 Jul 2022, 18:44
Have you examined the key history to see what is happening?

If you direct AHK to send a lowercase W, then that is what it will do. The other way:

Code: Select all

~d Up::Send {Blind}w
See https://www.autohotkey.com/docs/commands/Send.htm#blind

Test in Notepad.
Thanks bro that helped.

I didnt manage to make setkeydelay to work but i turn around with sleep funtion.

Can u give me an exemple (in my script) on how to insert the setbatchline (or other fast input function) and also a function to control how long the key should be pressed?

Thank you

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

Re: Need to improve my script pls help  Topic is solved

Post by mikeyww » 23 Jul 2022, 10:27

Code: Select all

SetBatchLines -1

~d Up::
SetKeyDelay,, PRESSDURATION := 50
Send {Blind}w
Return

HH_Comando
Posts: 6
Joined: 19 Jul 2022, 12:29

Re: Need to improve my script pls help

Post by HH_Comando » 24 Jul 2022, 15:11

Thank u sir. That solved my problem.

HH_Comando
Posts: 6
Joined: 19 Jul 2022, 12:29

Re: Need to improve my script pls help

Post by HH_Comando » 08 Aug 2022, 16:59

mikeyww wrote:
23 Jul 2022, 10:27

Code: Select all

SetBatchLines -1

~d Up::
SetKeyDelay,, PRESSDURATION := 50
Send {Blind}w
Return
Hey Mike can u help me here again?

If i want it to work instead of keyup but at the moment the key is pressed?

i want to when i press "A" key for it to press W briefly and then keep A pressed as it would normally (but not W again, just once when i press the key).

How can i do it?

i tried something like

~a::
Send {w 1}
Sleep, 1
Send a

but it just repeats the "W" when A is being pressed and i just want "W" key to be happens once, in the begining of the key press.

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

Re: Need to improve my script pls help

Post by mikeyww » 08 Aug 2022, 18:14

Code: Select all

$a::
Send w
While GetKeyState("a", "P")
 Send a
Return

HH_Comando
Posts: 6
Joined: 19 Jul 2022, 12:29

Re: Need to improve my script pls help

Post by HH_Comando » 11 Aug 2022, 16:07

mikeyww wrote:
08 Aug 2022, 18:14

Code: Select all

$a::
Send w
While GetKeyState("a", "P")
 Send a
Return
That worked thanks!

what "$" before the keystroke means?


Post Reply

Return to “Gaming Help (v1)”