I need help improving an AHK.

Get help with using AutoHotkey and its commands and hotkeys
Posts: 36
Joined: 10 Dec 2019, 22:02

I need help improving an AHK.

17 Dec 2019, 21:20

Good night,
I am trying to write a macro that does the following:
I wanted that when I press ctrl I activate a sequence in A, S, D, W and loop these keys until I separate ctrl to deactivate the sequence.
Can anybody help me?

[Mod edit: Topic moved.]
Posts: 49
Joined: 16 Jul 2017, 14:49
GitHub: mshafer1

Re: I need help improving an AHK.

17 Dec 2019, 22:20

A) post in these questions under "Ask for Help" (as opposed to "Tutorials")

> CTRL + I = loop ASDW till released

Check out: https://autohotkey.com/board/topic/72012-solved-loop-while-pressed-only/

In theory, this should work (untested)

Code: Select all

  while GetKeyState("Ctrl","P")
   Send, A
   Send, S
   Send, D
   Send, W
Or AHKGen.com link: https://www.ahkgen.com/?length=1&commen ... on0=Custom
Posts: 17
Joined: 18 Dec 2019, 03:39

Re: I need help improving an AHK.

18 Dec 2019, 06:45

Hey this should help!

Code: Select all

#SingleInstance, force
SendMode Input
SetBatchLines, -1

global TheKey := "Ctrl"
global Keys := ["A", "S", "D", "W"]
global KeyCounter := 1
global TimeFromKeyToKey := 100 ; you can adjust this time to your liking

Loop {
    CurrentKeyState := GetKeyState(TheKey, "P")

    if(CurrentKeyState) {

        if(KeyCounter > 4) {
            KeyCounter := 1

    Sleep, %TimeFromKeyToKey%

PressKey(key) {
    SendInput, {%key% down}
    Sleep, 25
    SendInput, {%key% up}


Return to “Ask For Help”

Who is online

Users browsing this forum: charge, Google [Bot], hasantr, RubbeH, songdg and 50 guests