Hi,
I'm new to AutoHotKey, and with a lot of copy/pasting and retrying i finally got the script I should want, but something is wrong with the timeouts work, especially when the get looped/repeated.
The point of my script :
To execute keystroke combination (SPACE followed by cursorDOWN) for a specified multiply of times.
I have some program where i need to check a bunch of tickmarks (using SPACE) and then move down to the next one, and repeat the process.
The routine itself is triggered by pressing the F7 key.
To enhance it some more and not having to run the script over and over again to check another bunch of tickmarks, i added a timeout to the F7 hotkey, so that, after it executed x times SPACE + DOWN, if i press the hotkey F7 again within 5 seconds, the process repeats, otherwise the script must exit.
The problem :
It seems like, with even F7 hotkey press i do, the 5 seconds timeout doesn't get respected, but is actually added up with each run.
Moreover, once in a while during this abnormally long timeout, the process triggers as if i pressed F7, when i did NOT.
The script :
Code:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; Pop up the Question how many times to repeat the Space + DOWN event.
InputBox, SendCount, Space and Down Repeat, How many time do I loop the Space and Down event ?, , 640, 480
if ErrorLevel
{
MsgBox, CANCEL was pressed.
Goto Exit
}
; Pop up the Question to first highlight the window & place where to start & ask to press F7 to start the process.
MsgBox, Now highlight the window and its item where we need to start the repeating`nand press F7 to start.`nThe repeating will happen %SendCount% times.`n`nTip: If you press F7 again in the next 5 seconds, the process will repeat itself`n,if not, the automation will exit.
KeyWait, F7, D
KeyWait, F7
;Set the delay (waiting time between keypresses) to 50 milliseconds.
SetKeyDelay, 50
DoTheLoop:
Loop %SendCount%
{
Send {Space} ; Presses the SPACE key.
Send {Down} ; Presses the DOWN arrow key.
}
; If F7 is pressed again in the next 5 seconds, the process will be repeated.
KeyWait, F7, D T5
KeyWait, F7
if ErrorLevel
{ ; No more F7 press detected, exitting..
Goto Exit
}
else
{
Goto DoTheLoop
}
Exit:
Exit
Attention ! Precautions to take to testrun this script safely.
- Make sure you have notepad running with a blank document open, and in the foreground BEFORE you press F7 !!!
Please, can anyone help me out what could be the problem, or if this could indeed be a bug in the wait the "KeyWait" timeout (or perhaps any timeout) is behaving ?
Thanks for any helpful response.