This script does not yet account for the affect of using FIP_SCANPIXELS nor does it yet allow you to use a file as the haystack.
To use this:
Create your needle image then making sure that there is something on the screen for your needle to match, run the script. A dialog will popup with choices that match FindImagePos> parameters. If you are at all familiar with FindImagePos> the choices will be obvious. If you're not familiar this may provide a way to become familiar with the way the function works.
All feedback welcome. What would make this better?
Code: Select all
OnEvent>Key_Down,VK27,0,HaltProcess
Dialog>ImageSizeDialog
object ImageSizeDialog: TForm
Color = 16777207
object MSImage1: tMSImage
AutoSize = True
end
end
EndDialog>ImageSizeDialog
Dialog>Dialog1
object Dialog1: TForm
Left = 441
Top = 210
HelpContext = 5000
AlphaBlend = True
BorderIcons = [biSystemMenu, biMinimize]
Caption = 'Highlight Found Image(s)'
ClientHeight = 300
ClientWidth = 522
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
Position = poScreenCenter
ShowHint = True
OnTaskBar = True
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 429
Top = 16
Width = 48
Height = 13
Caption = 'Tolerance'
end
object Label2: TLabel
Left = 24
Top = 120
Width = 105
Height = 13
Caption = 'Needle File (Required)'
end
object Label3: TLabel
Left = 24
Top = 168
Width = 66
Height = 13
Caption = 'HayStack File'
end
object Label4: TLabel
Left = 24
Top = 224
Width = 112
Height = 13
Caption = 'HighLight Color Number'
end
object Label5: TLabel
Left = 187
Top = 224
Width = 116
Height = 13
Caption = 'Highlight Line Thickness'
end
object Label6: TLabel
Left = 330
Top = 272
Width = 3
Height = 13
end
object MSRadioGroup1: tMSRadioGroup
Left = 11
Top = 16
Width = 118
Height = 64
Caption = 'Match Type'
ItemIndex = 0
Items.Strings = (
'Exact'
'CCOEFF')
TabOrder = 0
Text = 'Exact'#13#10'CCOEFF'#13#10
end
object MSRadioGroup2: tMSRadioGroup
Left = 199
Top = 16
Width = 138
Height = 78
Caption = 'Haystack Type'
ItemIndex = 0
Items.Strings = (
'File'
'SCREEN'
'Window')
TabOrder = 1
Text = 'File'#13#10'SCREEN'#13#10'Window'#13#10
end
object Edit1: TEdit
Left = 421
Top = 36
Width = 60
Height = 21
TabOrder = 2
Text = '0'
end
object Edit2: TEdit
Left = 16
Top = 138
Width = 457
Height = 21
TabOrder = 3
end
object Edit3: TEdit
Left = 16
Top = 186
Width = 454
Height = 21
TabOrder = 4
end
object Edit4: TEdit
Left = 16
Top = 240
Width = 64
Height = 21
TabOrder = 5
Text = '255'
end
object Edit5: TEdit
Left = 178
Top = 240
Width = 63
Height = 21
TabOrder = 6
Text = '3'
end
object MSButton1: tMSButton
Left = 485
Top = 137
Width = 21
Height = 21
Glyph.Data = {
F6000000424DF600000000000000760000002800000010000000100000000100
0400000000008000000000000000000000001000000010000000000000000000
80000080000000808000800000008000800080800000C0C0C000808080000000
FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00777777777777
77777777777777777777000000000007777700333333333077770B0333333333
07770FB03333333330770BFB0333333333070FBFB000000000000BFBFBFBFB07
77770FBFBFBFBF0777770BFB0000000777777000777777770007777777777777
7007777777770777070777777777700077777777777777777777}
TabOrder = 7
DoBrowse = False
Filter =
'BMP files (*.bmp)|*.BMP|PNG files (*.png)|*.PNG|Any file (*.*)|*' +
'.*'
BrowseStyle = fbOpen
end
object MSButton2: tMSButton
Left = 485
Top = 185
Width = 21
Height = 21
Glyph.Data = {
F6000000424DF600000000000000760000002800000010000000100000000100
0400000000008000000000000000000000001000000010000000000000000000
80000080000000808000800000008000800080800000C0C0C000808080000000
FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00777777777777
77777777777777777777000000000007777700333333333077770B0333333333
07770FB03333333330770BFB0333333333070FBFB000000000000BFBFBFBFB07
77770FBFBFBFBF0777770BFB0000000777777000777777770007777777777777
7007777777770777070777777777700077777777777777777777}
TabOrder = 8
DoBrowse = False
Filter =
'BMP files (*.bmp)|*.BMP|PNG files (*.png)|*.PNG|Any file (*.*)|*' +
'.*'
BrowseStyle = fbOpen
end
object MSButton3: tMSButton
Left = 356
Top = 234
Width = 75
Height = 25
Caption = 'Process'
TabOrder = 9
DoBrowse = False
BrowseStyle = fbOpen
end
object MSButton4: tMSButton
Left = 440
Top = 234
Width = 75
Height = 25
Caption = 'Clear Screen'
TabOrder = 18
DoBrowse = False
BrowseStyle = fbOpen
end
end
EndDialog>Dialog1
AddDialogHandler>Dialog1,MSButton1,OnClick,DoBrowse1
AddDialogHandler>Dialog1,MSButton2,OnClick,DoBrowse2
AddDialogHandler>Dialog1,MSButton3,OnClick,Process
AddDialogHandler>Dialog1,MSButton4,OnClick,ClearScreen
AddDialogHandler>Dialog1,MSRadioGroup1,OnClick,FixForRG1
AddDialogHandler>Dialog1,MSRadioGroup2,OnClick,FixForRG2
SetDialogObjectFont>Dialog1,Label6,Arial,12,1,255
SetDialogProperty>Dialog1,MSRadioGroup2,ItemIndex,1
Let>HaltProcessFlag=0
Show>Dialog1,res1
GoSub>ClearScreen
SRT>Process
GetDialogProperty>Dialog1,Edit1,Text,Tolerance
GetDialogProperty>Dialog1,Edit2,Text,ImageFile
IfFileExists>ImageFile
ExtractFileExt>ImageFile,FileExt
UpperCase>FileExt,FileExt
GetDialogProperty>Dialog1,MSRadioGroup1,ItemIndex,Selected1
If>Selected1=0
If>FileExt=.BMP
Else
MDL>"%ImageFile%"%CRLF%is not a BMP file
Goto>EndProcess
EndIf
Else
If>{(%FileExt%=".BMP")or(%FileExt%=".PNG")}
Else
MDL>"%ImageFile%"%CRLF%is not a BMP or PNG file
Goto>EndProcess
EndIf
EndIf
Else
MDL>"%ImageFile%" not valid
Goto>EndProcess
EndIf
SetDialogProperty>ImageSizeDialog,MSImage1,LoadImage,ImageFile
//SetDialogProperty>Dialog1,,AlphaBlendValue,0
Let>WIN_USEHANDLE=1
WindowAction>2,Dialog1.handle
Let>WIN_USEHANDLE=0
GetDialogProperty>ImageSizeDialog,MSImage1,Width,Xpixels
GetDialogProperty>ImageSizeDialog,MSImage1,Height,Ypixels
GetDialogProperty>Dialog1,MSRadioGroup1,SelectedItem,Selected1
GetDialogProperty>Dialog1,MSRadioGroup2,SelectedItem,Selected2
If>Selected2={"Window"}
GetDialogProperty>Dialog1,Edit3,Text,WinName
SetDialogProperty>Dialog1,Edit3,Text,
IfWindowOpen>%WinName%
SetFocus>%WinName%
Let>Selected2=WINDOW:%WinName%
SetDialogProperty>Dialog1,Edit3,Text,WinName
Else
MDL>Window: %WinName%%crlf%Not Found...%crlf%%crlf%Window names must be exact. No wildcards allowed.
SetDialogProperty>Dialog1,Edit3,Text,WinName
Let>WIN_USEHANDLE=1
WindowAction>0,Dialog1.handle
Let>WIN_USEHANDLE=0
Goto>EndProcess
EndIf
EndIf
FindImagePos>ImageFile,Selected2,Tolerance,0,Xpos,Ypos,numfound,Selected1
SetDialogProperty>Dialog1,Label6,Left,330
SetDialogProperty>Dialog1,Label6,Caption,NumFound = %NumFound%
SetDialogProperty>Dialog1,,Caption,NumFound = %NumFound%
If>numfound>0
GetDialogProperty>Dialog1,Edit4,Text,LineColor
GetDialogProperty>Dialog1,Edit5,Text,LineWeight
Let>kk=-1
Repeat>kk
If>HaltProcessFlag=1
Let>HaltProcessFlag=0
Goto>EndProcess
EndIf
Add>kk,1
SetDialogProperty>Dialog1,,Caption,NumFound = %kk% of %NumFound%
Let>XStart=Xpos_%kk%
Let>YStart=Ypos_%kk%
Let>Xend={%XStart%+%Xpixels%}
Let>Yend={%YStart%+0}
GoSub>DrawLine,0,LineWeight,LineColor,XStart,YStart,XEnd,YEnd
Let>XStart=XEnd
Let>YStart=YEnd
Let>Xend={%XEnd%+0}
Let>Yend={%YEnd%+%Ypixels%}
GoSub>DrawLine,0,LineWeight,LineColor,XStart,YStart,XEnd,YEnd
Let>XStart=XEnd
Let>YStart=YEnd
Let>Xend={%XEnd%-%Xpixels%}
Let>Yend={%YEnd%+0}
GoSub>DrawLine,0,LineWeight,LineColor,XStart,YStart,XEnd,YEnd
Let>XStart=XEnd
Let>YStart=YEnd
Let>Xend={%XEnd%+0}
Let>Yend={%YEnd%-%Ypixels%}
GoSub>DrawLine,0,LineWeight,LineColor,XStart,YStart,XEnd,YEnd
Until>kk={%numfound%-1}
SetDialogProperty>Dialog1,,Caption,NumFound = %NumFound%
Else
MDL>Needle image not found...%crlf%%crlf%Try adjusting the Tolerance setting.
EndIf
Label>EndProcess
End>Process
SRT>FixForRG1
GetDialogProperty>Dialog1,MSRadioGroup1,ItemIndex,Selected1
//Exact Selected
If>Selected1=0
SetDialogProperty>Dialog1,Edit1,Text,0
//CCOEFF Selected
Else
SetDialogProperty>Dialog1,Edit1,Text,0.7
EndIf
END>FixForRG1
SRT>FixForRG2
GetDialogProperty>Dialog1,MSRadioGroup2,ItemIndex,Selected2
//File Selected
If>Selected2=0
SetDialogProperty>Dialog1,MSRadioGroup2,ItemIndex,1
SetDialogProperty>Dialog1,Label6,Left,16
SetDialogProperty>Dialog1,Label6,Caption,Working with Haystack file not yet supported
SetDialogProperty>Dialog1,Label3,Caption,HayStack File
SetDialogProperty>Dialog1,Label3,Visible,True
SetDialogProperty>Dialog1,MSButton2,Visible,True
SetDialogProperty>Dialog1,Edit3,Enabled,True
Else
SetDialogProperty>Dialog1,MSButton2,Visible,False
//SCREEN Selected
If>Selected2=1
SetDialogProperty>Dialog1,Edit3,Enabled,False
SetDialogProperty>Dialog1,Label3,Visible,False
//Window Selected
Else
SetDialogProperty>Dialog1,Label3,Caption,Window Name
SetDialogProperty>Dialog1,Label3,Visible,True
SetDialogProperty>Dialog1,Edit3,Enabled,True
EndIf
EndIf
END>FixForRG2
//DrawLine Usage:
//GoSub>DrawLine,WindowHandle,PenSize,PenColor,XStart,YStart,XEnd,YEnd
SRT>DrawLine
LibFunc>user32,GetDC,HDC,%DrawLine_var_1%
LibFunc>gdi32,CreatePen,Penres,0,%DrawLine_var_2%,%DrawLine_var_3%
LibFunc>gdi32,SelectObject,SOPres,hdc,Penres
Libfunc>gdi32,MoveToEx,mtres,HDC,%DrawLine_var_4%,%DrawLine_var_5%,0
LibFunc>gdi32,LineTo,ltres,hdc,%DrawLine_var_6%,%DrawLine_var_7%
LibFunc>gdi32,DeleteObject,DOres,Penres
LibFunc>user32,ReleaseDC,RDCres,HDC_1,HDC
END>DrawLine
SRT>DoBrowse1
SetDialogProperty>Dialog1,MSButton1,DoBrowse,True
GetDialogProperty>Dialog1,MSButton1,Filename,strFileName1
SetDialogProperty>Dialog1,Edit2,Text,strFileName1
END>DoBrowse1
SRT>DoBrowse2
SetDialogProperty>Dialog1,MSButton2,DoBrowse,True
GetDialogProperty>Dialog1,MSButton2,Filename,strFileName2
SetDialogProperty>Dialog1,Edit3,Text,strFileName2
END>DoBrowse2
SRT>ClearScreen
SetDialogProperty>ImageSizeDialog,,BorderStyle,bsNone
SetDialogProperty>ImageSizeDialog,,AlphaBlend,False
Let>WIN_USEHANDLE=1
WindowAction>2,Dialog1.handle
WindowAction>1,ImageSizeDialog.handle
SetFocus>ImageSizeDialog.handle
WindowAction>0,Dialog1.handle
Let>WIN_USEHANDLE=0
SetDialogProperty>Dialog1,Label6,Caption,
SetDialogProperty>ImageSizeDialog,,AlphaBlend,True
SetDialogProperty>ImageSizeDialog,,AlphaBlendValue,0
END>ClearScreen
SRT>HaltProcess
Let>HaltProcessFlag=1
END>HaltProcess