Reputation: 83437
I have the following AutoHotKey script that uses A_ThisHotkey
:
spamLimit(limitTime)
{
send %A_ThisHotkey%
}
p::spamLimit(500)
How comes pressing P doesn't send the letter p
but instead open the following window
?
Upvotes: 2
Views: 1394
Reputation: 83437
It is simply looping p
-> start the command associated with the p
hotkey -> send p
-> start the command associated with the p
hotkey -> send p
-> …
To prevent this behavior, you can use the command Hotkey
to temporarily disable the hotkey. Example:
spamLimit(limitTime)
{
Hotkey, %A_ThisHotkey%, off
send %A_ThisHotkey%
}
p::spamLimit(500)
Another solution is using $
when defining the command, which forces the hook in the hotkey, i.e. disallows the hotkey to be triggered by its own send commands and generally most other virtual (non-physical) key presses. Example (one needs to use the function StringReplace
, otherwise it outputs $p
instead of p
.):
spamLimit(limitTime)
{
StringReplace, key, A_ThisHotkey, $, , All
send %key%
sleep limitTime
}
$p::spamLimit(500)
Upvotes: 3