如何使用自动热键选择特定选项卡?

如何使用自动热键选择特定选项卡?

我有一个带有自定义控件的窗口,其中包含一个标签栏控件,例如:

Tab 1 | Tab 2 | Tab 3 | Tab 4 | ...

我想选择选项卡 1(或选项卡 N)。当我激活窗口时,焦点可以在选项卡 1 到选项卡 N 之间的任何位置。

我知道有一种(在我看来)丑陋的方法,即将窗口设置为特定大小,然后单击选项卡的坐标。我也可以选择选项卡栏,然后计算 x 轴上的位置。这两种方法都不合适,因为窗口布局可以配置,我希望解决方案可以在不同的计算机上工作。

有没有更优雅的方式来使用可见文本选择一个控件?

如何使用自动热键或类似程序选择标签栏上的单个选项卡?

答案1

您是否考虑过图像搜索。您可以裁剪每个选项卡的图像,无论是处于活动状态还是非活动状态 [背景会改变颜色]。然后搜索特定图像并使用坐标进行点击。不过裁剪时要非常小心,一个小小的变化 [例如相邻选项卡的背景] 可能会导致此操作失败。

;CoordMode Pixel  ; Interprets the coordinates below as relative to the     screen rather than the active window.
ImageSearch, FoundX, FoundY, 0, 0, 200, 200, C:\Temp\Tab1.bmp ; search for image in area staring at 0,0 to 200,200
if ErrorLevel = 2
    MsgBox Could not conduct the search.
else if ErrorLevel = 1
    MsgBox Image could not be found on the screen.
else
    SoundBeep, 1000, 1000
    MsgBox The Image was found at %FoundX% %FoundY%.
    ClickX:=FoundX + 5 ; Move the mouse click away from the edge of the icon
    ClickY:=FoundY + 5 ; Move the mouse click away from the edge of the icon
    Click, %ClickX%, %ClickY% ; Click on the Save As icon.
Return

相关内容