Spamming - With Hold
_This Rapid fire script may be accurately referred to as a 'spamming' script because it simulates repeatedly hitting a single specific key. It is unique in how it knows what key to send, and can employ the same code with any number of keys simply by adding hotkeys to call the “spam” subroutine. The script will continue to send whichever hotkey is used to call the subroutine for as long as that key is held down.
#usehook ;*1 hotkey, left, spam ;*2 hotkey, up, spam ;*3 hotkey, right, spam ;*4 hotkey, down, spam ;*5 return spam: ;*6 { while getkeystate(a_thishotkey, "p") ;*7 { sleep 50 ;*8 sendinput, {%a_thishotkey%} ;*9 } } return end::exitapp ;*10 /* 1 Directs subsequent hotkeys to use the keyboard hook. 2 Uses Hotkey Command to create a left button hotkey tied to the spam subroutine. 3 Uses Hotkey Command to create a up button hotkey tied to the spam subroutine. 4 Uses Hotkey Command to create a right button hotkey tied to the spam subroutine. 5 Uses Hotkey Command to create a down button hotkey tied to the spam subroutine. 6 Spam subroutine label. When called, any code below it will run. 7 While loop and getkeystate, will loop as long as the originating hotkey is held. 8 50ms sleep between loops. 9 Each loop run sends whichever hotkey originated the subroutine. 10 Emergency shutdown. */ |
_Some of you may be wondering why anyone would need a script to repeatedly send the same key, doesn't it do that when you hold down a key anyway? Yes, and no. When you hold down a key while typing in a text editor you will see the same character typed repeatedly, but the key is not actually being sent to the system repeatedly. Instead, the key is sent once but the keyboard driver sees that the key is not being released and creates the afore mentioned spamming effect. But in some applications, such as video games, the driver is not part of what is going on. It is in these situations that a spamming script can be of use.