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

19

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

无论如何,是否有一种方法可以编写批处理文件或其他脚本,以便在脚本运行时自动单击鼠标指针所在位置?我的主要目标是:

  1. 运行脚本
  2. 检查时间是否在00:00am和05:00am之间
  3. 如果不是,请继续每15分钟运行检查。
  4. 如果是,则检查当前机器上是否有互联网连接
  5. 如果有互联网连接,则继续运行脚本检查每15分钟。
  6. 如果没有互联网连接,则在鼠标指针指向的任何位置自动执行左键单击。
  7. 继续每15分钟运行并执行以上相同的检查

再次强调,我不知道这是否可能,只是想试一试。提前致谢!


2
如果这个论坛不适合发布这个问题,请不要恶意对待。请告诉我正确的论坛,我们可以关闭这个帖子并转移到正确的论坛。谢谢! - user818700
是的,这些事情是可能的。不,我们不会为您编写它。不过,您最好使用Windows PowerShell,因为批处理环境受到了愚蠢的限制。PowerShell可以访问系统中几乎所有的内容。 - Marc B
1
@MarcB 谢谢Marc,我并没有让你替我写代码,我完全有能力自己写。如果你能给我指明方向,比如提到PowerShell,我会去查一下的,感激不尽。 - user818700
2
我会使用AutoIt。在我看来,AutoIt更适合运行脚本,其中系统托盘图标可能比控制台窗口更可取。 - rojo
@rojo - 看起来非常有前途,谢谢! - user818700
3个回答

20

以防有些可怜的灵魂某天偶然发现这个,使用AutoIt,正如@rojo上面建议的 - 这是我编写的脚本,实现了我需要的功能:

; 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

好了,将代码保存在一个以 .au3 为扩展名的文件中,双击即可享受。


15

7

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接