鼠标点击按钮
Mouseclick on Button
我用 tkinter 编写了一个简约的 python 程序,它在单击按钮时给出示例文本。我现在想执行这个程序并点击带有autoit的按钮:
#include <MsgBoxConstants.au3>
#include <AutoItConstants.au3>
CalcTime()
Func CalcTime()
Run("dist/min_tk_app.exe")
Local $aPos = ControlGetPos("[CLASS:Button; INSTANCE:1]", "", "Edit1")
MsgBox($MB_SYSTEMMODAL, "", $aPos)
MouseClick($MOUSE_CLICK_LEFT, 324, 145, 1)
EndFunc
我通过 Autoit Window Info 应用程序收到此信息:[CLASS:Button; INSTANCE:1]
。我总是只收到 0
作为 $aPos
的输出。你知道为什么会这样吗?
我假设您收到 0
作为 $aPos
的输出,因为 Window 还不存在。您可以在处理 window:
之前尝试使用 WinWait
Run("dist/min_tk_app.exe")
; wait 10 seconds for the window to appear
WinWait("[CLASS:YourApp]", "", 10)
; maybe wait another second
Sleep(1000)
Local $aPos = ControlGetPos("[CLASS:Button; INSTANCE:1]", "", "Edit1")
如果@mrt 的解决方案不起作用,我建议使用 ControlFocus
将焦点设置在控件上,然后 ControlSend
发送控件上的输入按钮。通常确定按钮是预选的。如果不是这种情况,那么您可以发送 TAB 直到按钮获得焦点并发送回车。
你用的ControlGetPos
错了。
ControlGetPos ( "title", "text", controlID )
[CLASS:Button; INSTANCE:1]
应该放在 controlID
并且不要忘记 window 的标题(重要)!
无论如何,您应该使用 ControlClick
而不是 ControlGetPos
和 MouseClick
$WinTitle = "" ; put your window title here MANDATORY or it will use active window
$WinText = "" ;can be left empty
ControlClick($WinTitle, $WinText, "[CLASS:Button; INSTANCE:1]")
我用 tkinter 编写了一个简约的 python 程序,它在单击按钮时给出示例文本。我现在想执行这个程序并点击带有autoit的按钮:
#include <MsgBoxConstants.au3>
#include <AutoItConstants.au3>
CalcTime()
Func CalcTime()
Run("dist/min_tk_app.exe")
Local $aPos = ControlGetPos("[CLASS:Button; INSTANCE:1]", "", "Edit1")
MsgBox($MB_SYSTEMMODAL, "", $aPos)
MouseClick($MOUSE_CLICK_LEFT, 324, 145, 1)
EndFunc
我通过 Autoit Window Info 应用程序收到此信息:[CLASS:Button; INSTANCE:1]
。我总是只收到 0
作为 $aPos
的输出。你知道为什么会这样吗?
我假设您收到 0
作为 $aPos
的输出,因为 Window 还不存在。您可以在处理 window:
WinWait
Run("dist/min_tk_app.exe")
; wait 10 seconds for the window to appear
WinWait("[CLASS:YourApp]", "", 10)
; maybe wait another second
Sleep(1000)
Local $aPos = ControlGetPos("[CLASS:Button; INSTANCE:1]", "", "Edit1")
如果@mrt 的解决方案不起作用,我建议使用 ControlFocus
将焦点设置在控件上,然后 ControlSend
发送控件上的输入按钮。通常确定按钮是预选的。如果不是这种情况,那么您可以发送 TAB 直到按钮获得焦点并发送回车。
你用的ControlGetPos
错了。
ControlGetPos ( "title", "text", controlID )
[CLASS:Button; INSTANCE:1]
应该放在 controlID
并且不要忘记 window 的标题(重要)!
无论如何,您应该使用 ControlClick
ControlGetPos
和 MouseClick
$WinTitle = "" ; put your window title here MANDATORY or it will use active window
$WinText = "" ;can be left empty
ControlClick($WinTitle, $WinText, "[CLASS:Button; INSTANCE:1]")