PressNHold [Function]
Posted: 03 Sep 2017, 11:09
Ok, since the community get's asked this so many times, I might as well make a simple and easy to use Press and Hold script.
Here's the function with an example:
Explaination:
This allows, when F1 is pressed, to "spam" the space key with a delay of 10 milliseconds.
To do multiple keys, do as follows:
Explanation:
Upon pressing F1, again, will "spam" ab repeatedly until you let go of F1.
Any questions can be asked here and if you need anything, I'll be having fun under the sun. (Not really because I never go outside :P)
Here's the function with an example:
Code: Select all
F1::PressNHold(A_ThisHotkey, "{space}", 10)
PressNHold(Key, Press := "", Delay := 100) {
While (GetKeyState(Key, "P")) {
SendInput % (Press) ? Press : Key
Sleep % Delay
}
}
This allows, when F1 is pressed, to "spam" the space key with a delay of 10 milliseconds.
To do multiple keys, do as follows:
Code: Select all
F1::PressNHold(A_ThisHotkey, "ab", 10)
PressNHold(Key, Press := "", Delay := 100) {
While (GetKeyState(Key, "P")) {
SendInput % (Press) ? Press : Key
Sleep % Delay
}
}
Upon pressing F1, again, will "spam" ab repeatedly until you let go of F1.
Any questions can be asked here and if you need anything, I'll be having fun under the sun. (Not really because I never go outside :P)