Below script works fine.
It sends mouse clicks every 4 seconds to KingSoft Writer. But when I change the Timer length to -4000 instead of 4000 so that the timer will run only once the script no longer works even once. I am no longer able to send mouse clicks to KingSoft Writer. What am I doing wrong?
#Persistent
#SingleInstance
SetTimer, CheckApp, 4000
Return
CheckApp:
IfWinActive, ahk_class QWidget
{
sleep 2000
Click 486, 15
Click 570, 93
}
Return
Before I answer this question. Would you be so kind as to go back to the previous question and mark the answer you received there, by clicking on the WHITE check-mark to turn it GREEN.
I once tried the minus values and was not happy with the results, so I decided to always turn the timer off instead of using negative values.
#Persistent
#SingleInstance
SetTimer, CheckApp, 4000
Return
CheckApp:
IfWinActive, ahk_class QWidget
{
SetTimer, CheckApp, Off
Click 486, 15
Click 570, 93
}
Return
I removed your Sleep, 2000. Adding this sleep command blocks ahk 50% of the time (sleeping 50%) and adds nothing useful. It even makes the chance that another application steals the focus in those 2 seconds larger, so the mouse clicks could go to another application... Do you have to use mouse clicks or can you use keyboard shortcuts. Mouse positions tend to be unreliable as menus move or expand/contract.
#Persistent
#SingleInstance
Return ; Prevent the [Win]+w from executing on startup of script.
#w:: ; [Win]+w launches PolyEdit, waits for window and sends two mouse clicks.
Run, path to the PolyEdit window.exe
WinWaitActive, ahk_class QWidget
Sleep, 1000
Click 486, 15
Click 570, 93
Return
Now you can put the ahk script in the windows start menu and launch PolyEdit through [Win]+w (or any other key you define...)
Not sure why you want to do this, because launching the app takes an action (clicking an icon or pressing a shortcut), which could be used to trigger the script. Now you have to constantly run checks in the background. You can create an icon that looks like KingSoft, but in reality is an ahk script.
But here you go!
#Persistent
#SingleInstance
SetTimer, CheckApp, 400
Return
InitiateKS := true
CheckApp:
IfWinExist, ahk_class QWidget
{
If InitiateKS
{
InitiateKS := false
WinActivate, ahk_class QWidget
TrayTip, KingSoft, Started, 1
;Click 486, 15
;Click 570, 93
}
}
Else ; if no KingSoft is running
{
InitiateKS := true
}
Return