AutoHotkey - 如何单击 ClassNN 发生变化的控件?
AutoHotkey - How to click a control whose ClassNN changes?
我正在尝试使程序中的工作流程自动化,但遇到了障碍。我通常使用 ControlClick
单击按钮,但对于此特定控件,每次程序重新加载时 ClassNN
都会更改。我尝试使用控件文本,但是 window 中有两个控件具有相同的文本并且它似乎阻止命令执行。
还有什么我可以尝试让 ControlClick
工作的吗?或者我可以采取另一种方法吗?我不想在 (x,y) 坐标处单击,因为控件可能会根据用户的分辨率和任务窗格大小移动。
我使用的命令是:
ControlClick, checkButton3, Bystronic BySoft 7
这适用于其他相邻按钮,因为它们具有独特的控制文本。
尝试这样的事情:
WinGet, List, ControlList, Bystronic BySoft 7
Loop, Parse, List, `n
{
If InStr(A_LoopField, "WindowsForms10.Window") ; use only the part of the name that is always shown in WS
{
ControlGetText, Text, %A_LoopField%, Bystronic BySoft 7
If InStr(Text, "checkButton3")
{
ControlGetPos, XX, YY, WW, HH, %A_LoopField%, Bystronic BySoft 7
If (XX < ... && YY... &&...) ; relative position, you don't have to define it exactly)
{
ControlClick, %A_LoopField%, Bystronic BySoft 7
break
}
}
}
}
编辑:
如果控件总是以相同的顺序检查,你可以试试这个:
Index := ""
WinGet, List, ControlList, Bystronic BySoft 7
Loop, Parse, List, `n
{
If InStr(A_LoopField, "WindowsForms10.Window") ; use only the part of the name that is always shown in WS
{
ControlGetText, Text, %A_LoopField%, Bystronic BySoft 7
If (Text = "checkButton3")
{
Index++
If (Index = 2) ; try also "If (Index = 3)" and "If (Index = 4)" until you find the right one. If "If (Index = 1)" is the right one you don't need the variable Index.
{
ControlClick, %A_LoopField%, Bystronic BySoft 7
break
}
}
}
}
我在一个应用程序中遇到了同样的问题。两个按钮交换 ClassNN。
称它们为按钮 %Up% 和 %Down%。它们是 Button7 或 Button9,可以是 WindowsForms 10.xxx.yyy.zzz 1234 或 WindowsForms 10.xxx.yyy.zzz 1235.
我应该注意到这两个按钮总是以上两个值之一。应用程序中的所有其余控件保持不变。一旦应用 运行,%Up% 和 %Down% 按钮就不会改变。
在应用程序开始时,我使用 ControlGetPos for WindowsForms 10.xxx.yyy.zzz 1234 和另一个 ControlGetPos for WindowsForms 10.xxx.yyy.zzz 1235.
寻找两个按钮的位置
%Up% 按钮在屏幕上的 %Down% 按钮上方,因此屏幕位置较高的 ControlGetPos 变为 %Up%,另一个变为 %Down%
ControlClick,%Up%,Wintitle。 %Up% 是 WindowsForms 10.xxx.yyy.zzz 123?较高的屏幕位置
无论屏幕分辨率如何,按钮相对于其他按钮的位置决定了它的标签。
我正在尝试使程序中的工作流程自动化,但遇到了障碍。我通常使用 ControlClick
单击按钮,但对于此特定控件,每次程序重新加载时 ClassNN
都会更改。我尝试使用控件文本,但是 window 中有两个控件具有相同的文本并且它似乎阻止命令执行。
还有什么我可以尝试让 ControlClick
工作的吗?或者我可以采取另一种方法吗?我不想在 (x,y) 坐标处单击,因为控件可能会根据用户的分辨率和任务窗格大小移动。
我使用的命令是:
ControlClick, checkButton3, Bystronic BySoft 7
这适用于其他相邻按钮,因为它们具有独特的控制文本。
尝试这样的事情:
WinGet, List, ControlList, Bystronic BySoft 7
Loop, Parse, List, `n
{
If InStr(A_LoopField, "WindowsForms10.Window") ; use only the part of the name that is always shown in WS
{
ControlGetText, Text, %A_LoopField%, Bystronic BySoft 7
If InStr(Text, "checkButton3")
{
ControlGetPos, XX, YY, WW, HH, %A_LoopField%, Bystronic BySoft 7
If (XX < ... && YY... &&...) ; relative position, you don't have to define it exactly)
{
ControlClick, %A_LoopField%, Bystronic BySoft 7
break
}
}
}
}
编辑:
如果控件总是以相同的顺序检查,你可以试试这个:
Index := ""
WinGet, List, ControlList, Bystronic BySoft 7
Loop, Parse, List, `n
{
If InStr(A_LoopField, "WindowsForms10.Window") ; use only the part of the name that is always shown in WS
{
ControlGetText, Text, %A_LoopField%, Bystronic BySoft 7
If (Text = "checkButton3")
{
Index++
If (Index = 2) ; try also "If (Index = 3)" and "If (Index = 4)" until you find the right one. If "If (Index = 1)" is the right one you don't need the variable Index.
{
ControlClick, %A_LoopField%, Bystronic BySoft 7
break
}
}
}
}
我在一个应用程序中遇到了同样的问题。两个按钮交换 ClassNN。
称它们为按钮 %Up% 和 %Down%。它们是 Button7 或 Button9,可以是 WindowsForms 10.xxx.yyy.zzz 1234 或 WindowsForms 10.xxx.yyy.zzz 1235.
我应该注意到这两个按钮总是以上两个值之一。应用程序中的所有其余控件保持不变。一旦应用 运行,%Up% 和 %Down% 按钮就不会改变。
在应用程序开始时,我使用 ControlGetPos for WindowsForms 10.xxx.yyy.zzz 1234 和另一个 ControlGetPos for WindowsForms 10.xxx.yyy.zzz 1235.
寻找两个按钮的位置%Up% 按钮在屏幕上的 %Down% 按钮上方,因此屏幕位置较高的 ControlGetPos 变为 %Up%,另一个变为 %Down%
ControlClick,%Up%,Wintitle。 %Up% 是 WindowsForms 10.xxx.yyy.zzz 123?较高的屏幕位置
无论屏幕分辨率如何,按钮相对于其他按钮的位置决定了它的标签。