简体   繁体   中英

AutoHotKey not finding image on a window

I recently discovered AutoHotKey, this scripting language seemed to be amazing !

Unfortunately, I can't manage to make my script find an image on a window (BlueStacks in my case). Can someone please help me, my script is:

CoordMode, Pixel, screen
CoordMode, Mouse, screen

*ESC::ExitApp

ImgFound := false

while(ImgFound = false)
{
  ImageSearch, ButtonX, ButtonY, 0, 0, A_ScreenWidth, A_ScreenHeight, *50 C:\Users\...\Documents\...\test.png
  if (ErrorLevel = 2)
  {
      MsgBox Could not execute script.
      ExitApp
  }
  else if (ErrorLevel = 1)
  {
    ImgFound := false
  }
  else
  {
      MsgBox Found.
      click, %ButtonX%, %ButtonY%
      ImgFound := true
  }
}




Your while loop is unreachable code.
The code execution stops when the first hotkey label is encountered. This is called the Auto-execute Section .

Move your hotkey definition to be at the very bottom.
(All hotkeys always defined by hotkeys labels get always created regardless of being in the auto-execute section or not)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM