This is made for a program with a very non-consistent user interface, there is several graphical "versions" of the same button and it might be located at different places at toolbar depending on what element user has selected. The user interface requires the user to almost exclusively use the mouse for any action, eg. the keyboard delete button doesn't work - user have to use the mouse and locate the delete button.
Another problem with the user interface that the function deals with - the buttons on the program interface require that mouse hovers over for a while, before it can accept mouse click.
Also - the functions that deals with image search does store the last found position of image. At next call to same image search function, it only use imagesearch in the area that has same size as the image.
There is also a function that display the indexes and the orders and hit ratio for each index, so the user can easily see what function finds it's image most times.
Also there is some thing I've found out myself to improve the script:
- orderOfFunctionsSorted and countingEachIndex don't need to exist globally. I did make those global this because I originally planned a onExit() function that would write the order to an INI-file.
- need to catch errors from KlikkHoverVentFargeChange() (function is used by other functions in main script - 7k lines) that will stop the function in case delete-button in the program user interface doesn't react on mouse hovering over the button within a given time.
- some functions need to be renamed (easier to understand it purposes), and also the image names that doesn't completely match the names of functions.
- nnnik: Script is said to be "cancerous" -- may nnnik explain in detail.
- serg : "Gdip_ImageSearch" by MasterFocus is much faster than native "ImageSearch" -- Does it work on x64? Can Gdip_ImageSearch specify color variations?
- nnnik: Maybe a Shape search algorythm -- Doesn't that require reading a lot of "PixelGetColor" to fill a pixel table? Have my doubt in that.
Nb: Large part of the delay is because the program require mouse pointer to hover over the button, I cannot change that.
Appreciate any feedback that contributes to even better image search performance. But - it must work at win64 and support color variations.
I attach some sample images that show the image used by imagesearch (no because forum bug).
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
orderOfFunctionsSorted := [6,5,4,3,1,2,7,8] ; May read this from ini-file but for this specific user interface, that would not gain any advantages
countingEachIndex := [0,0,0,0,0,0,0,0]
; Search for delete-button. Maximum performance and use as little resources as possible.
sletteknappFinnTrykk() {
Global orderOfFunctionsSorted, countingEachIndex
mainLoop_sletteknapp:
Loop, 8
{
func_index := orderOfFunctionsSorted[A_Index]
returverdi := sletteknappFinnTrykk_U%func_index%()
If (returverdi == 1) {
If (A_Index == 1) {
countingEachIndex[1]++
Break, mainLoop_sletteknapp
}
Else {
; ACTION 1 - add "points" to whatever index that lead to first function that returned 1
countingEachIndex[A_Index]++
index_last_used_last := A_Index -1
; ACTION 2 - sorting
loop_search_all_decending_sletteknapp:
Loop, %index_last_used_last%
{
index_less_than_next := A_index
If (countingEachIndex[A_Index+1] > countingEachIndex[A_Index]) {
; sort
status_sorted_secondary := 0
loop_sort_bubble_sletteknapp:
While, !status_sorted_secondary
{
loop_bakover_sletteknapp:
Loop, %index_less_than_next%
{
status_sorted_secondary := 1
i_bakover := index_last_used_last - A_index +1 ; searching backwards
If ( countingEachIndex[i_bakover+1] > countingEachIndex[i_bakover] ) {
; swap contents at countingEachIndex[]
hitCounts_temp := countingEachIndex[i_bakover]
countingEachIndex[i_bakover] := countingEachIndex[i_bakover+1]
countingEachIndex[i_bakover+1] := hitCounts_temp
; swap contents at orderOfFunctionsSorted[]
rekkefolge_temp := orderOfFunctionsSorted[i_bakover]
orderOfFunctionsSorted[i_bakover] := orderOfFunctionsSorted[i_bakover+1]
orderOfFunctionsSorted[i_bakover+1] := rekkefolge_temp
}
}
} ; while "not sorted"
}
Else ; next one is already bigger - skip
Continue, loop_search_all_decending_sletteknapp
} ; sort main
Break
}
}
} ; Loop outer
}
; menu_slett3.bmp size 18x21 Offset: 21x25 offset-img-coords_bg-color-change: 4x4
sletteknappFinnTrykk_U1() {
Static funnetX, funnetY, x2, y2
If (funnetX) { ; SMALL SEARCH
ImageSearch, funnetX, funnetY, funnetX, funnetY, x2, y2, *44 menu_slett3.bmp
If (!errorlevel) {
KlikkHoverVentFargeChange(funnetX+18, funnetY+25, funnetX+4, funnetY+4)
Return 1
}
}
ImageSearch, funnetX, funnetY, 104, 53, 1282, 125, *44 menu_slett3.bmp
If (!errorlevel) { ; Large Area Search (LAS)
x2 := funnetX + 18
y2 := funnetY + 21
KlikkHoverVentFargeChange(funnetX+7, funnetY+7, funnetX+10, funnetY+13)
Return 1
}
}
; menu_slett4.bmp size 18x16 Offset: 9x8 offset-img-coords_bg-color-change: 2x6
sletteknappFinnTrykk_U2() {
Static funnetX, funnetY, x2, y2
If (funnetX) { ; SMALL SEARCH
ImageSearch, funnetX, funnetY, funnetX, funnetY, x2, y2, *44 menu_slett4.bmp
If (!errorlevel) {
KlikkHoverVentFargeChange(funnetX+9, funnetY+8, funnetX+2, funnetY+6)
Return 1
}
}
ImageSearch, funnetX, funnetY, 104, 53, 1282, 125, *44 menu_slett4.bmp
If (!errorlevel) { ; Large Area Search (LAS)
x2 := funnetX + 18
y2 := funnetY + 16
KlikkHoverVentFargeChange(funnetX+7, funnetY+7, funnetX+10, funnetY+13)
Return 1
}
}
; menu_slett2.bmp size 38x50 Offset: 16x22 offset-img-coords_bg-color-change: 27x25
sletteknappFinnTrykk_U3() {
Static funnetX, funnetY, x2, y2
If (funnetX) { ; SMALL SEARCH
ImageSearch, funnetX, funnetY, funnetX, funnetY, x2, y2, *44 menu_slett2.bmp
If (!errorlevel) {
KlikkHoverVentFargeChange(funnetX+16, funnetY+22, funnetX+27, funnetY+25)
Return 1
}
}
ImageSearch, funnetX, funnetY, 396,54, 452,122, *44 menu_slett2.bmp
If (!errorlevel) {
x2 := funnetX + 38
y2 := funnetY + 50
KlikkHoverVentFargeChange(funnetX+7, funnetY+7, funnetX+10, funnetY+13)
Return 1
}
ImageSearch, funnetX, funnetY, 104, 53, 1282, 125, *44 menu_slett2.bmp
If (!errorlevel) { ; Large Area Search (LAS)
x2 := funnetX + 38
y2 := funnetY + 50
KlikkHoverVentFargeChange(funnetX+7, funnetY+7, funnetX+10, funnetY+13)
Return 1
}
}
; Same image as for sletteknappFinnTrykk_U6 - but another area (2) to search.
sletteknappFinnTrykk_U4() {
Static funnetX, funnetY, x2, y2
If (funnetX) { ; SMALL SEARCH
ImageSearch, funnetX, funnetY, funnetX, funnetY, x2, y2, *44 menu_slett7.bmp
If (!errorlevel) {
KlikkHoverVentFargeChange(funnetX+10, funnetY+11, funnetX+7, funnetY+6)
Return 1
}
}
ImageSearch, funnetX, funnetY, 105,96, 149,124, *44 menu_slett7.bmp
If (!errorlevel) {
x2 := funnetX + 14
y2 := funnetY + 14
KlikkHoverVentFargeChange(funnetX+7, funnetY+7, funnetX+10, funnetY+13)
Return 1
}
}
; Same image as for sletteknappFinnTrykk_U6 - but another area (3) to search.
sletteknappFinnTrykk_U5() {
Static funnetX, funnetY, x2, y2
If (funnetX) { ; SMALL SEARCH
ImageSearch, funnetX, funnetY, funnetX, funnetY, x2, y2, *44 menu_slett7.bmp
If (!errorlevel) {
KlikkHoverVentFargeChange(funnetX+5, funnetY+5, funnetX+10, funnetY+11)
Return 1
}
}
ImageSearch, funnetX, funnetY, 888,72, 920,102, *44 menu_slett7.bmp
If (!errorlevel) { ; normalt avgrenset søk (NAS) - normalt å finne knappen akkurat her (trase)
x2 := funnetX + 14
y2 := funnetY + 14
KlikkHoverVentFargeChange(funnetX+7, funnetY+7, funnetX+10, funnetY+13)
Return 1
}
}
; This image search is most likely to find the image.
sletteknappFinnTrykk_U6() {
Static funnetX, funnetY, x2, y2
If (funnetX) { ; SMALL SEARCH
ImageSearch, funnetX, funnetY, funnetX, funnetY, x2, y2, *44 menu_slett7.bmp
If (!errorlevel) {
KlikkHoverVentFargeChange(funnetX+6, funnetY+6, funnetX+10, funnetY+12)
Return 1
}
}
ImageSearch, funnetX, funnetY, 406,96, 470,124, *44 menu_slett7.bmp
If (!errorlevel) { ; normalt avgrenset søk (NAS) - normalt å finne knappen akkurat her (normale nettkomponenter)
x2 := funnetX + 14
y2 := funnetY + 14
KlikkHoverVentFargeChange(funnetX+7, funnetY+7, funnetX+10, funnetY+13)
Return 1
}
; Default menu - button should not exist outside the given areas. Uncomment this to allow searcing on a bigger area.
/*
ImageSearch, funnetX, funnetY, 104, 53, 1282, 125, *44 menu_slett7.bmp
If (!errorlevel) { ; Large Area Search (LAS)
x2 := funnetX + 14
y2 := funnetY + 14
KlikkHoverVentFargeChange(funnetX+7, funnetY+7, funnetX+10, funnetY+13)
Return 1
}
*/
}
; menu_slett7b.bmp size 17x15 Offset: 7x7 offset-img-coords_bg-color-change: 10x13
sletteknappFinnTrykk_U7() {
Static funnetX, funnetY, x2, y2
If (funnetX) { ; SMALL SEARCH
ImageSearch, funnetX, funnetY, funnetX, funnetY, x2, y2, *44 menu_slett7b.bmp
If (!errorlevel) {
KlikkHoverVentFargeChange(funnetX+7, funnetY+7, funnetX+10, funnetY+13)
Return 1
}
}
ImageSearch, funnetX, funnetY, 104, 53, 1282, 125, *44 menu_slett7b.bmp
If (!errorlevel) { ; Large Area Search (LAS)
x2 := funnetX + 17
y2 := funnetY + 15
KlikkHoverVentFargeChange(funnetX+7, funnetY+7, funnetX+10, funnetY+13)
Return 1
}
}
; menu_slett8.bmp size 16x12 Offset: 7x5 offset-img-coords_bg-color-change: 2x5
sletteknappFinnTrykk_U8() {
Static funnetX, funnetY, x2, y2
If (funnetX) { ; SMALL SEARCH
ImageSearch, funnetX, funnetY, funnetX, funnetY, x2, y2, *44 menu_slett8.bmp
If (!errorlevel) {
KlikkHoverVentFargeChange(funnetX+7, funnetY+5, funnetX+2, funnetY+5)
Return 1
}
}
ImageSearch, funnetX, funnetY, 104, 53, 1282, 125, *44 menu_slett8.bmp
If (!errorlevel) { ; Large Area Search (LAS)
x2 := funnetX + 16
y2 := funnetY + 12
KlikkHoverVentFargeChange(funnetX+7, funnetY+7, funnetX+10, funnetY+13)
Return 1
}
}
; View contents in array - gives user an overview of what functions does find image most often.
arrayContentText2(arrayID, counterArray) {
textOut := "Index`t`tVerdi`t`tTellinger`n"
For i , Value in arrayID
textOut .= i . "`t-`t" . Value . "`t-`t" . counterArray[i] . "`n"
TrayTip, Verdi i tabell,%textOut%
}
; Mouse must hover over a button, and only when some areas of that buttons changes color - it allow the user to click on the button.
; Button in user interface won't respond if mouse click and moves too fast. Also it is not a fixed time delay.
; Throws error when timeout.
KlikkHoverVentFargeChange(klikkeX, klikkeY, fargePixelX, fargePixelY, mousePointerReturns:=1, max_waiting_time:=700) {
MouseGetPos, musX, musY
maxTid := A_TickCount + max_waiting_time
PixelGetColor, button_std_bg_color, fargePixelX, fargePixelY, RGB ; Hente farge1
MouseMove, klikkeX, klikkeY, 0
Sleep 50
Loop, 3000 ; Looking for change in pixel value.
{
If (A_TickCount > maxTid)
Throw "Timeout max time"
PixelGetColor, button_color_possiblechanged, fargePixelX, fargePixelY, RGB
If (button_color_possiblechanged != button_std_bg_color) {
Send, {LButton down}
Sleep 50
Send, {LButton up}
Sleep 50
If mousePointerReturns
MouseMove, musX, musY, 0
Return 1
}
If A_Index >= 3000
Throw "Timeout - counting to max"
}
}
https://autohotkey.com/boards/viewtopic ... 87#p121587
[edit]
Forum gives error message when I tries to upload png images - size of those images is as small as possible - smallest is 14x14 px and biggest is 38x50 px.
Error
Could not upload attachment to ./files/60087_b6fc2f6aadbc21b63611f09ce2994a6b.