I need help improving an AHK.

Get help with using AutoHotkey and its commands and hotkeys
kjaty
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.]
mshafer1
Posts: 49
Joined: 16 Jul 2017, 14:49
GitHub: mshafer1
Contact:

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")

B):
> 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

^i::
  while GetKeyState("Ctrl","P")
  {
   Send, A
   Send, S
   Send, D
   Send, W
  }
  return
Or AHKGen.com link: https://www.ahkgen.com/?length=1&commen ... on0=Custom
ivanthedevil
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

#NoEnv
#Persistent
#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) {
        PressKey(Keys[KeyCounter])
        
        KeyCounter++

        if(KeyCounter > 4) {
            KeyCounter := 1
        }
    }

    Sleep, %TimeFromKeyToKey%
}

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

$Ctrl::return

Return to “Ask For Help”

Who is online

Users browsing this forum: boiler, keylo, mikeyww, RubbeH, songdg, william_ahk and 48 guests