SHARE
TWEET

Universal ImageSearch GUI

a guest Jun 10th, 2019 108 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #SingleInstance Force
  2. CoordMode, Mouse
  3. CoordMode, Pixel
  4.  
  5. ClientEXE := "client.exe"
  6. interval := 100
  7. offsetX := 2
  8. offsetY := 2
  9. shades := 2
  10.  
  11. Gui, +ToolWindow +AlwaysOnTop +HwndMainHWND
  12. Gui, Font, S8 CDefault, Verdana
  13.  
  14. Gui, Add, Tab3, hwndTabHWND, Search|Options|On Find Actions
  15. Gui, Tab, 1
  16.  
  17. Gui, Add, GroupBox, section h110 w100, Image
  18. Gui, Add, Picture, hwndPicHWND xp+10 yp+20 h80 w80
  19. Gui, Add, DDL, Disabled y+17 xp-10  w100 Choose1 vimageFile gImageChange, % Images
  20. Gui, Add, Button, Disabled wp+1 hp gSubmit hwndStartStop, Start
  21. Gui, Add, Edit, vLogEdit ys+6 h158 w260 ReadOnly
  22.  
  23. Gui, Tab, 2
  24. Gui, Add, Text, , Image Folder
  25. Gui, Add, Edit, section r1 Disabled w220 vimgDirectory,
  26. Gui, Add, Button, ys-1 gSelectImageFolder, Browse...
  27.  
  28. ;Refresh Images
  29. Gui, Add, Button, ys-1 wp gRefreshImages, Refresh
  30.  
  31. ;Search Interval
  32. Gui, Add, Text, x21 yp+30 Section ,Search Interval [ms]
  33. Gui, Add, Edit, number wp vInterval gIntervalChange center, % interval
  34.  
  35. ;Shades
  36. Gui, Add, Text, ys wp x+20, Variation
  37. Gui, Add, Edit, limit3 w100 number center gVariationChange
  38. Gui, Add, UpDown, Range0-255 vShades gVariationChange, % shades
  39.  
  40. ;Killswitch
  41. Gui, Add, Text, ys x+20, Killswitch
  42. Gui, Add, Hotkey, w113 vKillswitch, F7
  43.  
  44. ;Client EXE
  45. Gui, Add, Text, xs Section y+10, Client EXE Name
  46. Gui, Add, Edit, w120 center vClientEXE disabled, % ClientEXE
  47.  
  48. ;SearchScreen
  49. Gui, Add, CheckBox,  ys+23 center vSearchScreen gSearchEntireScreen checked, Search Entire Screen Instead of EXE?
  50.  
  51. Gui, Tab, 3
  52.  
  53. ;OnFound
  54. Gui, Add, Text, xs Section y+10, Action when image is found:
  55. Gui, Add, DDL, w200 center vFoundAction altsubmit gUpdateVars, Mouse Click Image||Mouse Move to Image|Log Only
  56.  
  57. ;StopIfFound
  58. Gui, Add, Text, xs Section y+10, Keep searching if image is found?
  59. Gui, Add, DDL, w200 center vStopIfFound altsubmit gUpdateVars, Stop if the image is found||Continue Searching at Interval
  60.  
  61. ;Show
  62. Gui, Show, Autosize , Image Search
  63.  
  64. Log("Ready")
  65.  
  66. return
  67.  
  68. SearchEntireScreen:
  69.     Gui, Submit, Nohide
  70.     GuiControl, % (SearchScreen ? "Disable" : "Enable"), ClientEXE
  71. Return
  72.  
  73. ImageChange:
  74.     Gui, Submit, Nohide
  75.     GuiControl,, % picHWND, % imgDirectory "\" imageFile ".png"
  76.     GuiControl, Move, Static1,  h80 w80
  77. Return
  78.  
  79. IntervalChange:
  80.     Gui, Submit, Nohide
  81.     If !Interval{
  82.     Interval := 1
  83.     GuiControl,,Interval, % Interval
  84.     }
  85. Return
  86.  
  87. UpdateVars:
  88.     Gui, Submit, Nohide
  89. Return
  90.  
  91. VariationChange:
  92.     Gui, Submit, Nohide
  93.     GuiControl,,Shades, % Shades
  94. Return
  95.  
  96. Search:
  97.     ;Search a specific window or just a client area?
  98.     If !(SearchScreen){
  99.         WinActivate, % "ahk_exe " ClientEXE
  100.         WinGetPos, cliX, cliY, cliW, cliH, % "ahk_exe " ClientEXE
  101.         ImageSearch, foundX, foundY, % cliX, % cliY, % cliX + cliW, % cliY + cliH, % "*" shades A_Space imgDirectory "\" imageFile ".png"
  102.     } else {
  103.         ImageSearch, foundX, foundY, 0, 0, % A_ScreenHeight, % A_ScreenWidth, % "*" shades A_Space imgDirectory "\" imageFile ".png"
  104.     }
  105.  
  106.     If !(ErrorLevel) {
  107.         If (FoundAction = 1)
  108.             MouseClick, Left, % foundX + offsetX, % foundY + offsetY, 1, 0
  109.         If (FoundAction = 2)
  110.             MouseMove, % FoundX, % FoundY, 0
  111.                
  112.         Log("Found " imageFile " at x:" foundX " y:" foundY)
  113.        
  114.         If (StopIfFound = 1)
  115.             GoSub, Submit
  116.     }
  117. Return
  118.  
  119. Submit:
  120.     Gui, Submit, Nohide
  121.     Toggle := !Toggle
  122.     If (Killswitch <> "")
  123.         Hotkey, % KillSwitch, Submit, % (Toggle ? "ON" : "OFF")
  124.     GuiControl, % Toggle ? "Disable" : "Enable", imageFile
  125.     GuiControl,, % StartStop, % Toggle ? "Stop" : "Start"
  126.     SetTimer, Search, % (Toggle) ? interval : "Off"
  127.     Log("Search " (Toggle ? "Started" : "Stopped") " - " imageFile)
  128. Return
  129.  
  130. Log(txt){
  131.     Global LogEdit
  132.     Gui, Submit, Nohide
  133.     FormatTime, time,, H:MM
  134.     GuiControl,, LogEdit, % time " - " txt "`n" LogEdit
  135. }
  136.  
  137. GuiClose:
  138. GuiEscape:
  139.     ExitApp
  140. Return
  141.  
  142. SelectImageFolder:
  143.     Gui, -AlwaysOnTop +Disabled
  144.     FileSelectFolder, Folder, % A_Desktop,,Select Image Folder
  145.     Gui, +AlwaysOnTop -Disabled
  146.     Gui, Show
  147.     If ErrorLevel
  148.         Return
  149.     GuiControl,,imgDirectory, % Folder
  150.     Gui, Submit, Nohide
  151. RefreshImages:
  152.     Gosub, Loadimages
  153.     GuiControl,, imageFile , % "|" Images  
  154.     GuiControl, Choose, % TabHWND, 1
  155.     GoSub ImageChange
  156. Return
  157.  
  158. LoadImages:
  159.     Images := ""
  160.     Loop, Files, % imgDirectory "\*.png"
  161.         Images .= Format("{:Ts}", StrReplace(A_LoopFileName, "." A_LoopFileExt)) "|" (A_Index = 1 ? "|" : "")
  162.     If (Images <> ""){
  163.         GuiControl, Enable, Start
  164.         GuiControl, Enable, ImageFile
  165.         Log("Image List Updated")
  166.     } else {
  167.         GuiControl, Disable, Start
  168.         GuiControl, Disable, ImageFile
  169.         Log("Folder contains no images")
  170.     }
  171. Return
  172.  
  173. ^Esc::Reload
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top