3

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
Dmitry Pavliv
  • 35,333
  • 13
  • 79
  • 80
user2216119
  • 55
  • 1
  • 4

1 Answers1

3

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.

Update

#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...)

Update 2

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
Community
  • 1
  • 1
Robert Ilbrink
  • 7,738
  • 2
  • 22
  • 32
  • I turned the white checkmark to green as you asked. I didn't know about this feature. Thanks for your excellent reply! I am currently getting close to a solution using the below script: #Persistent WinWaitActive, ahk_class TMainForm Send Now is the time Return The above script works. But it's lacking a major feature. I need to make it work when I close the current PolyEdit window and open a second PolyEdit window. Right now, that doesn't happen. Right now I have to reload the script before opening the second PolyEdit window. I don't want to reload the script. This is where I am lost. – user2216119 Mar 29 '13 at 16:42
  • In that situation, why not use the ahk script to launch the PolyEdit window with a hotkey. See modified script above. – Robert Ilbrink Mar 29 '13 at 17:43
  • I agree Robert. I'm very grateful for your input about how to accept an answer. I agree with you 100%. Regarding using a hotkey to launch the script. Yes, that works. But I was looking for a script that runs without a hotkey. Am I right in assuming that there isn't any? – user2216119 Mar 29 '13 at 21:34
  • I have to use mouse clicks. There are only a few Keyboard shortcuts and none of them are useful. – user2216119 Mar 30 '13 at 02:03
  • Wow! It worked! Robert, the script you added worked! It would have taken me months of study to make a script that worked. You are the man! I turned the checkmark green. Thanks. – user2216119 Mar 30 '13 at 14:45
  • @RobertIlbrink fair enough, but there's a world of difference between educating new users and holding an answer hostage for an accept. Like I said, it's noisy and no offense, but smells highly of rep whoring. – Mike G Apr 03 '13 at 12:39