Automate mouse click in windows with script/batch

2019-02-08 18:18发布

Firstly I'd like to point out that this is a rather strange question and also that I don't even know if stackoverflow is right for this...

Anyways, is there a way to write a batch file or some other script that will automate a mouse click wherever the mouse pointer happens to be at the time the script runs? My main goal is this:

  1. Run script
  2. Check if the time is between 00:00am and 05:00am
  3. If it's not then continue running checking every 15mins.
  4. If it IS, then check if there is internet connection on the current machine
  5. If there is internet connection then continue running script checking every 15mins.
  6. If there is NOT an internet connection then automate a left mouse click wherever the mouse pointer happens to be pointing at the time.
  7. Continue running doing the same checks as above every 15mins

Again I don't know even if this is possible, just thought I'd try my luck. Thanks in advance!

3条回答
劫难
2楼-- · 2019-02-08 18:32

Just in case some poor soul stumbles upon this one day, using AutoIt that @rojo suggested above - This is the script that I wrote that accomplishes what I need:

; Initiate Script
Main()

Func Main()
    ; Infinite loop
    While 0 < 1
        If CheckTime() == true Then
            If CheckInternetConnection() == true Then
                ; Internet Connection is true
                ; So no worries
            Else
                ; Internet Connection is false
                ; Perform mouse click
                MouseClick("left")
            EndIf       
        EndIf
        ; Sleep for 15 minutes
        Sleep(60000 * 15)
    WEnd
EndFunc

; The function checks if the current time is between 00:00 and 05:00
Func CheckTime()
    If @Hour >= 00 AND @Hour <= 05 Then
        Return true
    Else
        Return false
    EndIf
EndFunc

; The function checks if currently is a internet connection
Func CheckInternetConnection()
    Local $Connected = false
    $ping = Ping("www.google.com")
    If $ping > 0 Then
        $Connected = true
    EndIf
    Return $Connected
EndFunc

And there you go, just save the code in a file with a .au3 file extention, double click and enjoy.

查看更多
在下西门庆
3楼-- · 2019-02-08 18:40

nircmd is capable to do some basic mouse stuff. Check mouse.bat - self-compiled C# class (c# compiler is installed by default from everything from vista and above) capable to command the mouse from command line (also pretty basic but can do a little bit more than nircmd). with mouse.bat -help you can see the help and some example actions.

查看更多
趁早两清
4楼-- · 2019-02-08 18:57

I'd use AutoIt. IMHO, autoit is more appropriate for running scripts where a systray icon might be preferable to a console window. AutoIt can check the time, ping something, automate a mouse click, and probably whatever else you need.

查看更多
登录 后发表回答