Hi! I'm fairly new to coding with Autohotkey so please bear with me in my lack of breadth in explaining this issue or coding it properly.
I am trying to make a script that is able to accept an input time interval in minutes and then automatically calculate the next time to send a message.
I don't want to use a timer method because it is imperative that the timer acts on the closest millisecond to :00 seconds and I find that settimer and a sleep loop are unreliable.
Here is my code as of now:
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Event ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#Persistent
CoordMode, Mouse, Screen
SetTitleMatchMode, 2
SetKeyDelay, 0, 0
getx := 0
gety := 0
amsg := []
amsg[1]:= "blah"
bmsg := []
bmsg[1]:= "blah"
Loop {
if (A_min = 59 and A_sec = 59 and a_MSec >= 975) {
MouseGetPos, getx, gety
WinActivate, Google Chrome
Random, rand, 1, 20
MouseMove, 3082, 1362
MouseClick, left
Send, % bmsg[rand]
Send, {Enter}
MouseMove, %getx%, %gety%
Sleep, 1001
}
if (A_min = 09 and A_sec = 59 and a_MSec >= 975) {
MouseGetPos, getx, gety
WinActivate, Google Chrome
Random, rand, 1, 20
MouseMove, 3082, 1362
MouseClick, left
Send, % bmsg[rand]
Send, {Enter}
MouseMove, %getx%, %gety%
Sleep, 1001
}
if (A_min = 19 and A_sec = 59 and a_MSec >= 975) {
MouseGetPos, getx, gety
WinActivate, Google Chrome
Random, rand, 1, 20
MouseMove, 3082, 1362
MouseClick, left
Send, % bmsg[rand]
Send, {Enter}
MouseMove, %getx%, %gety%
Sleep, 1001
}
if (A_min = 29 and A_sec = 59 and a_MSec >= 975) {
MouseGetPos, getx, gety
WinActivate, Google Chrome
Random, rand, 1, 20
MouseMove, 3082, 1362
MouseClick, left
Send, % bmsg[rand]
Send, {Enter}
MouseMove, %getx%, %gety%
Sleep, 1001
}
if (A_min = 39 and A_sec = 59 and a_MSec >= 975) {
MouseGetPos, getx, gety
WinActivate, Google Chrome
Random, rand, 1, 20
MouseMove, 3082, 1362
MouseClick, left
Send, % bmsg[rand]
Send, {Enter}
MouseMove, %getx%, %gety%
Sleep, 1001
}
if (A_min = 49 and A_sec = 59 and a_MSec >= 975) {
MouseGetPos, getx, gety
WinActivate, Google Chrome
Random, rand, 1, 20
MouseMove, 3082, 1362
MouseClick, left
Send, % bmsg[rand]
Send, {Enter}
MouseMove, %getx%, %gety%
Sleep, 1001
}
}
return
For example, I would want to put in a start time of :10 and an interval of :03 and have it act at :13, :16, :19, :22, and so on.
Also, I had attempted to put the code within the if statements inside a function and repeat that, but it did not send messages the same as the method listed above. Any help?