![Trololol! :trollface:](./images/smilies/trollface.png)
![Read. :terms:](./images/smilies/terms.gif)
My idea is that the script presses the same key repeatedly and then holds down a key, then loops this process. I've tried it but it just ended up shaking my screen and closing the game I tried to do it on.
![Facepalm :facepalm:](./images/smilies/facepalm.png)
Please help me, AHK Community!
![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
Code: Select all
tgtwin = Untitled ;<- for the notepad window
settitlematchmode,2 ;<- so you don't need the whole nopad window title
detecthiddenwindows On ;<- so the script can detect the target window even if hidden
return
; example: loop the 1 key press 1 to start looping and press again to stop looping
; this script uses an untitled windows notepad window as the target to send the 1 key
; to. if the window becomes inactive or the 1 key is pressed again the script stops
; temporarily until the 1 key is pressed again and the notepad window is active
; to stop the script entirely press the esc key
; the message box at the end and the tooltip windows are there to let you know what
; the script is doing as it does it.
$1::
keywait, 1
looping := !looping ;<- toggle for looping the key
tooltip, Line%A_LineNumber% hotkey running. (looping = %looping%)...
while (looping) ;<- if looping is on
{ ifwinnotactive, %tgtwin% ;< if the notepad window is not active
{ looping = 0 ;<- set looping off
break ;<- and exit the loop
}
if (getkeystate("1","p")) ;<-if the one key is pressed again inside the loop
{ keywait 1 ;<- wait til the key is released
looping = 0 ;<- turn looping off
break ;<- and exit the loop
}
send 1 ;<- send the 1 key to the active window
sleep 200 ;<- sleep delay 2/10ths of a second
}
tooltip, Line%A_LineNumber% hotkey ended. (looping = %looping%)...
return ;<- end the loop but stay ready for more
esc:: ;<- exits the script entirely
tooltip ;<- turns off the tooltip message
MsgBox,0x1000,Line%A_LineNumber%,Script Ended. ;<- signals the end of the script
ExitApp
Users browsing this forum: mexican scientist and 64 guests