【问题标题】:Automate mouse click in windows with script/batch file使用脚本/批处理文件在窗口中自动单击鼠标
【发布时间】:2013-03-07 04:17:30
【问题描述】:

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

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

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

我也不知道这是否可能,只是想我会试试运气。 提前致谢!

【问题讨论】:

  • PS - 如果这恰好是错误的论坛,请不要吝啬。告诉我什么是正确的论坛,然后我们可以关闭这个并把它移过来。谢谢!
  • 是的,这样的事情是可能的。不,我们不会为你写的。不过,您最好使用 Windows PowerShell,因为批处理环境受到了愚蠢的限制。 powershell 几乎可以访问系统中的所有内容。
  • @MarcB 谢谢 Marc,我没有让你为我写代码,我非常有能力自己编写代码,谢谢。向正确方向简单推动将不胜感激,例如提及 powershell - 我会去检查一下。
  • 我会使用 autoit。恕我直言,autoit 更适合运行系统托盘图标可能比控制台窗口更可取的脚本。
  • @rojo - 看起来很有希望,谢谢!

标签: windows batch-file console-application


【解决方案1】:

以防万一有一天某个可怜的灵魂偶然发现了这一点,使用上面@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

然后,只需将代码保存在具有 .au3 文件扩展名的文件中,双击即可享受。

【讨论】:

    【解决方案2】:

    我会使用AutoIt。恕我直言,autoit 更适合运行系统托盘图标可能比控制台窗口更可取的脚本。 AutoIt 可以check the timeping somethingautomate a mouse click,可能还有whatever else you need

    【讨论】:

      【解决方案3】:

      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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-10-27
        • 1970-01-01
        • 1970-01-01
        • 2012-06-19
        相关资源
        最近更新 更多