Well actually I got it working, I was making a small tool to get the required data now.
Basically this is the script that has the two functions that do all the work, it's not to be opened but rather included:
include_me.au3
Code:
;this would be the file to be included in order to have
;available the following 2 functions,
;*************************************
;img_to_data(left, top, right, bottom)
;converts a box on the screen to data that can be
;compared later on by the other function
;return/example:
;=> color, width, height, checksum
;=> 2302746,32,33,273114417
;*************************************
;search_img(data)
;search the screen for a box of pixels with same checksum
;returns:
;=> false ;if no image found
;=> [$x, $y] ;an array containing the center of the image
Dim $_pos[2]
Func img_to_data($x0, $y0, $x1, $y1)
$_height = $y1 - $y0
$_width = $x1 - $x0
$_checksum = PixelChecksum ( $x0, $y0, $x1, $y1 )
$_color = PixelGetColor($x0, $y0)
$_data = $_color & "," & $_width & "," & $_height & "," & $_checksum
return $_data
EndFunc
Func search_img($data)
Tooltip("Searching...", 10, 10)
$_array = StringSplit($data, ",")
$_color = $_array[1]
$_width = $_array[2]
$_height = $_array[3]
$_checksum = $_array[4]
;It can only look so far
$_max_width = @desktopWidth - $_width
$_max_height = @desktopHeight - $_height
;Look the lazy way (pixel by pixel), perhaps could use PixelSearch
For $x = 0 To $_max_width
For $y = 0 To $_max_height
If $_color = PixelGetColor($x,$y) Then
$_data = img_to_data($x, $x + $_width, $y, $y + $_height)
$_array = StringSplit($_data, ",")
If $_array[4] = $_checksum Then
;I'm adding $_width/2 and $_height/2 to return the middle
$_pos[0] = $x + $_width/2
$_pos[1] = $y + $_height/2
Tooltip("")
return $_pos
EndIf
EndIf
Next
Next
Tooltip("")
return false
EndFunc
And the following is the tool to get the data required, basically you place your mouse over the top-left corner of whatever you're trying to read and press Numpad1, then place the mouse over the bottom-right corner and press Numpad2, this will read the data required within those two coordinates and copy it to your clipboard for further use, you can even see if it's working by pressing the HOME key.
tool.au3
Code:
#include "include_me.au3"
HotKeySet("{Numpad1}","pick_min")
HotKeySet("{Numpad2}","pick_max")
HotKeySet("{HOME}","test")
HotKeySet("{END}","close")
Dim $_x0,$_x1,$_y0,$_y1,$_img
Func info($txt)
Tooltip($txt, 10, 10)
EndFunc
info("Use Numpad1 to pick the top-left position of an object")
While 1
WEnd
Func pick_min()
$pos = MouseGetPos()
$_x0 = $pos[0]
$_y0 = $pos[1]
info("Use Numpad2 to pick the bottom-right position of an object")
EndFunc
Func pick_max()
$pos = MouseGetPos()
$_x1 = $pos[0]
$_y1 = $pos[1]
read_from_user()
EndFunc
Func read_from_user()
$_img = img_to_data($_x0, $_x1, $_y0, $_y1)
ClipPut( $_img )
info("Use HOME to test and find the object")
msgbox(48, "Alert", "The following data has been added to the clipboard" & @LF & $_img)
EndFunc
Func test()
$res = search_img($_img)
If isArray($res) Then
$x = $res[0]
$y = $res[1]
mousemove($x, $y)
msgbox(48, "Alert", "Object found at (" & $x & "," & $y & ")")
Else
msgbox(48, "Alert", "Object not found")
EndIf
EndFunc
Func Close()
Exit
EndFunc
And finally this is how you'd actually use it:
example.au3
Code:
#include "include_me.au3"
HotKeySet("{HOME}","test_me")
HotKeySet("{END}","close")
;this is one was taken for my res for the skill meditation
;so actually replace for one you get using the tool
$sample_skill = "2302746,32,33,273114417"
While 1
Wend
Func test_me()
add_ap($sample_skill)
EndFunc
;this is a way to use the search_img() function
Func add_ap($skill)
$res = search_img($sample_skill)
If isArray($res) Then
$x = $res[0]
$y = $res[1]
;replace the following with click and add offset if needed depending
;on how the data was taken, (x,y) corresponds to the middle of the object
mousemove($x, $y)
msgbox(48, "Alert", "Object found at (" & $x & "," & $y & ")")
Else
msgbox(48, "Alert", "Object not found")
EndIf
EndFunc
Func Close()
Exit
EndFunc
And I'm surprised how much you can copy on a single post lol