【问题标题】:Autohotkey - Trigger script when a certain button was clicked in a windowAutohotkey - 在窗口中单击某个按钮时触发脚本
【发布时间】:2013-02-28 06:12:51
【问题描述】:

我知道实际按钮的句柄。我想检查该按钮是否被点击,如果是的话会触发一个自动热键脚本。

提前致谢!

【问题讨论】:

    标签: button handle autohotkey buttonclick hwnd


    【解决方案1】:

    你是对的。您可以使用它来代替 ImgSearch。

    ControlGetPos, x, y, w, h, button1, ahk_class CalcFrame
    MsgBox, %x% %y% %w% %h%
    return
    

    因此,您必须在每次鼠标单击后运行 ControlGetPos(仅当目标窗口标题处于活动状态时),然后将实际鼠标坐标与按钮单击区域进行比较。

    这是计算器的一些代码:

    #SingleInstance Force
    #Persistent
    
    #IfWinActive, ahk_class CalcFrame
        ~LButton::
        MouseGetPos, MouseX, MouseY
        ControlGetPos, ButtonX, ButtonY, ButtonW, ButtonH, button1, ahk_class CalcFrame
        ButtonX2:=ButtonX + ButtonW
        ButtonY2:=ButtonY + ButtonH
        if MouseX between %ButtonX% and %ButtonX2%
        {
            if MouseY between %ButtonY% and %ButtonY2%
            {
                MsgBox, You pressed the MC button
            }
        }
        Return
    #IfWinActive
    

    【讨论】:

      【解决方案2】:

      您是否尝试过使用 ImgSearch 来“动态”查找按钮的 XY 坐标,然后执行 if (MouseX => ImageX and MouseX =

      伪代码(未测试):

      Settimer, FindButton, 1000
      Settitlematchmode, 2
      Return
      
      FindButton:
      IfWinActive, YourAppWindowTitle
          ImageSearch, ImageX, ImageY, 0, 0, A_ScreenWidth, A_ScreenHeight, C:\ButtonImage.bmp
      Return
      
      #IfWinActive, YourAppWindowTitle
      ~LButton::
      MouseGetPos, MouseX, MouseY
      if (MouseX => ImageX and MouseX =< ImageX + ImageWidth)
      {
          if (MouseY => ImageY and MouseY =< ImageY + ImageHeight)
          {
              Run your code here
          }
      }
      Return
      #IfWinActive
      

      【讨论】:

      • 这实际上不是一个坏主意。但是,我更愿意使用该按钮的句柄 ID,因为它更安全且不依赖于坐标(在其他 PC 上可能会更改)。
      • 我了解,可能值得寻找 ID 解决方案。我厌倦了用计时器来解决“移动”按钮(不同的屏幕、屏幕上移动的窗口等)的问题。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-14
      • 2018-08-20
      • 1970-01-01
      • 2013-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多