【问题标题】:PixelSearch not working correctly in AutoHotkey script after adding GUI添加 GUI 后,PixelSearch 在 AutoHotkey 脚本中无法正常工作
【发布时间】:2018-06-02 17:21:40
【问题描述】:

由于某种原因,即使在没有白色像素的黑色 PNG 文件上使用添加 GUI 后,下面的 PixelSearch 也无法正常工作。需要它作为循环的一部分工作。

    ;Pres P on keyboard to test
    p::SearchPixels()
    Esc::exitapp

    SearchPixels(){
    ;DefinRegion
    TLX = 1104
    TLY = 373
    BRX = 1422
    BRY = 452
    SomeText := "Found"
        Gui,+AlwaysOnTop
        Gui, Add, Text, cLime, %SomeText%
        Gui, Show, xCenter yCenter

              PixelSearch, FoundX, FoundY, TLX, TLY, BRX, BRY, 0xFFFFFF, 3, Fast RGB
              if ErrorLevel {
                 MsgBox Not Found
              } else {
                 MsgBox %SomeText%
              }


    Gui, Destroy ; Destroy the GUI
    Return
    }

但是,它在下面没有 GUI 的代码中可以正常工作。有没有办法在不使循环不起作用的情况下添加 GUI?

    ;Pres P on keyboard to test
    p::SearchPixels()
    Esc::exitapp

    SearchPixels(){
    ;DefinRegion
    TLX = 1104
    TLY = 373
    BRX = 1422
    BRY = 452
    SomeText := "Found"


              PixelSearch, FoundX, FoundY, TLX, TLY, BRX, BRY, 0xFFFFFF, 3, Fast RGB
              if ErrorLevel {
                 MsgBox Not Found
              } else {
                 MsgBox %SomeText%
              }

    Return
    }

【问题讨论】:

  • 很可能是 GUI 挡住了视图?还是背景窗口变暗,因为不再聚焦?

标签: loops user-interface autohotkey break


【解决方案1】:

在 AutoHotkey 论坛上被告知 CoordMode 可能是影响 PixelSearch 的原因。发现代码通过在第一行添加CoordMode,Pixel,Screen,如下所示。

    CoordMode, Pixel, Screen
    ;Pres P on keyboard to test
    p::SearchPixels()

    `::exitapp
     ^1::Reload

    SearchPixels(){
    Global Var
    ;DefinRegion
    SomeText = Found
    ;Coordinates gotten from the DefineBox(TLX, TLY, BRX, BRY, BW, BH) function found in DefineBox.ahk not added here for brevity.
    ;Screen size of 1920x1080
    TLX = 650
    TLY = 905
    BRX = 1281
    BRY = 983
        Gui,+LastFound +AlwaysOnTop -Caption +Owner
        Gui,+HWND_G
        CustomColor = EEAA99  ; Can be any RGB color.
        Gui, Color, %CustomColor%
        Size := 12
        FontType := "Verdana"
        Gui, Font, s%Size%, %FontType%
        GUIWidth = 500
        GUIHeight = 50
        Gui, Add, Text, x0 y1 W%GUIWidth% H%GUIHeight% cLime +Center vVar, 0
        ; Make all pixels of this color transparent and make the text itself translucent (150): 
        WinSet, TransColor, %CustomColor% 150
        TLXn := TLX - 10
        TLYn := TLY - 10
        BelowSearchArea := TLYn + GUIHeight
        CenterX := ((BRX - TLXn) / 2) + TLXn - (GUIWidth / 2)
        Gui, Show, x%CenterX% y%BelowSearchArea% W%GUIWidth% H%GUIHeight%

              Loop
              {
                  ;small adjustment based on something on my screen that I'm not sure about.
                  PixelSearch, FoundX, FoundY, TLXn, TLYn, BRX, BRY, 0xFFFFFF, 1, Fast RGB
                  if ErrorLevel {
                     GuiControl,,Var, 0
                  } else {
                     GuiControl,,Var, 1
                  }
              }
    Gui, Destroy ; Destroy the GUI
    Return
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-02
    • 1970-01-01
    • 2016-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多