使用脚本/批处理文件在Windows中自动鼠标单击

15 windows batch-file console-application

首先,我想指出这是一个相当奇怪的问题,我甚至不知道stackoverflow是否适合这个...

无论如何,有没有办法编写批处理文件或其他一些脚本,在脚本运行时鼠标指针恰好在哪里自动鼠标点击?我的主要目标是:

  1. 运行脚本
  2. 检查时间是否在00:00 am到05:00 am之间
  3. 如果没有,那么每15分钟继续运行检查.
  4. 如果是,则检查当前机器上是否有互联网连接
  5. 如果有互联网连接,则每15分钟继续运行脚本检查.
  6. 如果没有互联网连接,则在鼠标指针恰好指向时间的任何地方自动鼠标左键单击.
  7. 每15分钟继续运行与上述相同的检查

我再也不知道即使这是可能的,只是以为我会试试运气.提前致谢!

小智 16

为了防止一些可怜的灵魂在这一天遇到困难,使用@rojo上面提到的AutoIt - 这是我写的脚本,它完成了我需要的东西:

; 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
Run Code Online (Sandbox Code Playgroud)

然后你去,只需将代码保存在一个扩展名为.au3的文件中,双击即可享受.


roj*_*ojo 12

我使用AutoIt.恕我直言,autoit更适合运行脚本,其中系统托盘图标可能比控制台窗口更可取.AutoIt可以检查时间,ping某些东西,自动鼠标点击,以及可能你需要的任何其他东西.


npo*_*aka 5

nircmd能够做一些基本的鼠标操作。检查mouse.bat - 自编译的 C# 类(默认情况下从 vista 和更高版本安装了 C# 编译器)能够从命令行命令鼠标(也非常基本,但可以比 nircmd 做更多的事情)。与mouse.bat -help你能看到的帮助和一些示例动作。

这是示例用法:

例子:

::clicks at the current position
call mouse click

::double clicks at the current position
call mouse doubleClick

::right clicks at the current position
call mouse rightClick

::returns the position of the cursor
call mouse position

::scrolls up the mouse wheel with 1500 units
call mouse scrollUp 150

::scrolls down with 100 postitions
call mouse scrollDown 100

::relatively(from the current position) moves the mouse with 100 horizontal and 100 vertial postitions
call mouse moveBy 100x100

::absolute positioning
call mouse moveTo 100x100

::relative drag (lefclick and move)
call mouse dragBy 300x200

::absolute drag
call mouse dragTo 500x500
Run Code Online (Sandbox Code Playgroud)