我将解释一下我想让我的代码做什么:1.我将打开一个窗口2. 我将导航到那个窗口并按control+q3. 我将得到坐标与谷歌的功能,并将它们发布在输入框4。代码应该点击该窗口中的那个点,因为我选择的次数(我想在后台运行代码,因为我想在同一时间做另一个任务)。
我写了一些代码,但没有达到预期的效果。
#SingleInstance force
#persistent
$^q::
WinGetTitle, Title, A
MsgBox, The active window is "%Title%".
Inputbox, c1, , Coordinate of button you want to click on(x)
Inputbox, c2, , Coordinate of button you want to click on(y)
MsgBox %c1% , %c2%
Inputbox,times, ,How many times would you like to click?
While(times>0)
{
WinGet,b,,Title ;I think here is the problem
ControlClick, X%c1% Y%c2%,%b% ;or here
Sleep, 10500
times--
}
MsgBox End
return
确实有一些问题需要解决,不过解决了这些问题还是不能保证你的代码能够正常工作。ControlClick
ing是很会总是一拍即合的。
所以你最大的问题在这里 WinGet,b,,Title
都不知道这一行应该做什么。当然,你是想引用变量的 Title
你在上面定义的,如果要用传统的语法来做,你可以用 %%
. 也许你只是忘记了。但即使修好了,我也不知道为什么要用这个命令。你甚至没有指定使用哪个子命令,所以它默认为检索匹配窗口的hwnd。如果这确实是你我们要做的,那么你就需要修改 ControlClick
的 WinTitle 参数来指定您要根据窗口的 hwnd 进行匹配,就像这样。ControlClick, X%c1% Y%c2%, ahk_id %b%
根据窗口的hwnd来匹配窗口 实际上是匹配窗口的最佳做法 但你在这里的实现是有问题的。我觉得这甚至是个意外。尽管如此,让我把代码修改成更合理的实现hwnd匹配的方法。我也会把遗留的语法去掉,换成更新更好的表达式语法。
#SingleInstance, Force
#Persistent
$^q::
;ditched the legacy WinGetTitle command, and switched over to
;the WinActive function, its return value is the HWND of the
;matched window (active window)
ActiveWindowHWND := WinActive("A")
;getting the title as well, in case you really want to see it
;this part can be removed though
WinGetTitle, ActiveWindowTitle, % "ahk_id " ActiveWindowHWND
;concatenating strings and values by just separting them with a space
;and double quotes to escape a quote in an expression
;outer most quotes always just specify that we're writing a string
MsgBox, % "The active window's HWND is " ActiveWindowHWND " and its title is """ ActiveWindowTitle """"
;explicitly specifying that these long strings are actually strings
Inputbox, c1, , % "Coordinate of button you want to click on(x)"
Inputbox, c2, , % "Coordinate of button you want to click on(y)"
MsgBox, % c1 " , " c2
Inputbox, times, , % "How many times would you like to click?"
While (times > 0)
{
;specifying the NA option
;it's documented to improve reliablility, read more about it
;from the documentation
ControlClick, % "x" c1 " y" c2, % "ahk_id " ActiveWindowHWND, , , , NA
Sleep, 10500
times--
}
MsgBox, % "End"
return
如果你对更新更好的表达式语法完全不熟悉,你可以换回传统的语法,一样可以用。只要确保添加 NA
选项到控件clickThough我当然推荐使用新的表达式语法。这里有一个很好的文档页面可以让你入门。https:/www.autohotkey.comdocsLanguage.htm