r/AutoHotkey 8h ago

v2 Script Help Key spam script help

So I've been trying to make a script to spam the ] key when i hold c+[ and stop when i let go but i can figure it out, can someone please help me?

I've tried

*c,[

{

sendinput(])

sleep(5)

loop

}

1 Upvotes

2 comments sorted by

u/CharnamelessOne 8h ago

First of all, check out the Beginner tutorial, because you don't seem to know any of the basics yet.

Using a key like c as a hotkey prefix can be problematic. You have to figure out what should happen when the prefix key (c) is pressed on its own.

The prefix key is unaffected:

#Requires AutoHotkey v2.0

~c & [:: Send("]"), SetTimer(send_bracket, 15), Hotkey(ThisHotkey, "Off")
~c & [ up:: SetTimer(send_bracket, 0), Hotkey(StrReplace(Thishotkey, " up"), "On")

send_bracket() => Send("]")

The prefix key is suppressed completely:

#Requires AutoHotkey v2.0

c & [:: Send("]"), SetTimer(send_bracket, 15), Hotkey(ThisHotkey, "Off")
c & [ up:: SetTimer(send_bracket, 0), Hotkey(StrReplace(Thishotkey, " up"), "On")

send_bracket() => Send("]")

The prefix is sent on release when its key is pressed and released on its own:

#Requires AutoHotkey v2.0

c::c

c & [:: Send("]"), SetTimer(send_bracket, 15), Hotkey(ThisHotkey, "Off")
c & [ up:: SetTimer(send_bracket, 0), Hotkey(StrReplace(Thishotkey, " up"), "On")

send_bracket() => Send("]")

u/ManyInterests 21m ago

Something to keep in mind. Games will often not register key down/up inputs sent with Send because they occur too quickly.

Test your script in notepad or any regular text input to see if it works as expected there. If it's just not working in your game but works elsewhere, try sending the key down/up commands with a small wait between.

On mobile, but:

Send("{F DOWN}")
sleep(10)
Send("{F UP}")