windows 使用脚本/批处理文件在窗口中自动单击鼠标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15483420/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Automate mouse click in windows with script/batch file
提问by
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...
首先,我想指出这是一个相当奇怪的问题,而且我什至不知道 stackoverflow 是否适合这个问题......
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:
无论如何,有没有办法编写一个批处理文件或其他一些脚本来自动点击鼠标指针在脚本运行时鼠标指针所在的位置?我的主要目标是这样的:
- Run script
- Check if the time is between 00:00am and 05:00am
- If it's not then continue running checking every 15mins.
- If it IS, then check if there is internet connection on the current machine
- If there is internet connection then continue running script checking every 15mins.
- If there is NOT an internet connection then automate a left mouse click wherever the mouse pointer happens to be pointing at the time.
- Continue running doing the same checks as above every 15mins
- 运行脚本
- 检查时间是否在 00:00am 和 05:00am 之间
- 如果不是,则继续每 15 分钟运行一次检查。
- 如果是,则检查当前机器上是否有互联网连接
- 如果有互联网连接,则继续每 15 分钟运行一次脚本检查。
- 如果没有互联网连接,则在鼠标指针恰好指向的地方自动单击鼠标左键。
- 继续每 15 分钟执行一次与上述相同的检查
Again I don't know even if this is possible, just thought I'd try my luck. Thanks in advance!
我也不知道这是否可能,只是想试试我的运气。提前致谢!
采纳答案by rojo
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.
我会使用AutoIt。恕我直言, autoit 更适合运行脚本,其中系统托盘图标可能比控制台窗口更可取。AutoIt 可以检查时间、ping 某些东西、自动单击鼠标,以及您需要的任何其他东西。
回答by
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:
万一某个可怜的人有一天偶然发现了这一点,请使用@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
And there you go, just save the code in a file with a .au3 file extention, double click and enjoy.
好了,只需将代码保存在扩展名为 .au3 的文件中,双击即可享受。
回答by npocmaka
nircmdis 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.
nircmd能够做一些基本的鼠标操作。检查mouse.bat- 自编译的 C# 类(默认情况下从 vista 及以上的所有内容都安装了 c# 编译器)能够从命令行命令鼠标(也非常基本,但可以做的比 nircmd 多一点)。与mouse.bat -help
你能看到的帮助和一些示例动作。