It is used to find text or images on the screen.
Hope you like it !

Detailed usage can refer to:
1、The introduction by ed1chandler.
2、The introduction by c4p (latest).
Code: Select all
;/*
;===========================================
; FindText - Capture screen image into text and then find it
; https://autohotkey.com/boards/viewtopic.php?f=6&t=17834
;
; Author : FeiYue
; Version : 8.2
; Date : 2021-03-03
;
; Usage: (required AHK v1.1.31+)
; 1. Capture the image to text string.
; 2. Test find the text string on full Screen.
; 3. When test is successful, you may copy the code
; and paste it into your own script.
; Note: Copy the "FindText()" function and the following
; functions and paste it into your own script Just once.
; 4. The more recommended way is to save the script as
; "FindText.ahk" and copy it to the "Lib" subdirectory
; of AHK program, instead of copying the "FindText()"
; function and the following functions, add a line to
; the beginning of your script: #Include <FindText>
;
;===========================================
;*/
if (!A_IsCompiled and A_LineFile=A_ScriptFullPath)
FindText.Gui("Show")
;===== Copy The Following Functions To Your Own Code Just once =====
;--------------------------------
; FindText - Capture screen image into text and then find it
;--------------------------------
; returnArray := FindText(
; X1 --> the search scope's upper left corner X coordinates
; , Y1 --> the search scope's upper left corner Y coordinates
; , X2 --> the search scope's lower right corner X coordinates
; , Y2 --> the search scope's lower right corner Y coordinates
; , err1 --> Fault tolerance percentage of text (0.1=10%)
; , err0 --> Fault tolerance percentage of background (0.1=10%)
; , Text --> can be a lot of text parsed into images, separated by "|"
; , ScreenShot --> if the value is 0, the last screenshot will be used
; , FindAll --> if the value is 0, Just find one result and return
; , JoinText --> if the value is 1, Join all Text for combination lookup
; , offsetX --> Set the max text offset (X) for combination lookup
; , offsetY --> Set the max text offset (Y) for combination lookup
; , dir --> Five directions for searching: up, down, left, right and center
; )
;
; The function returns a second-order array containing
; all lookup results, Any result is an associative array
; {1:X, 2:Y, 3:W, 4:H, x:X+W//2, y:Y+H//2, id:Comment}
; if no image is found, the function returns 0.
; All coordinates are relative to Screen, colors are in RGB format
;
; If the return variable is set to "ok", ok.1 is the first result found.
; Where ok.1.1 is the X coordinate of the upper left corner of the found image,
; and ok.1.2 is the Y coordinate of the upper left corner of the found image,
; ok.1.3 is the width of the found image, and ok.1.4 is the height of the found image,
; ok.1.x <==> ok.1.1+ok.1.3//2 ( is the Center X coordinate of the found image ),
; ok.1.y <==> ok.1.2+ok.1.4//2 ( is the Center Y coordinate of the found image ),
; ok.1.id is the comment text, which is included in the <> of its parameter.
; ok.1.x can also be written as ok[1].x, which supports variables. (eg: ok[A_Index].x)
;
;--------------------------------
FindText(args*)
{
return FindText.FindText(args*)
}
Class FindText
{ ;// Class Begin
static bind:=[], bits:=[], Lib:=[]
__New()
{
this.bind:=[], this.bits:=[], this.Lib:=[]
}
__Delete()
{
if (this.bits.hBM)
DllCall("DeleteObject", "Ptr",this.bits.hBM)
}
FindText(x1:=0, y1:=0, x2:=0, y2:=0, err1:=0, err0:=0
, text:="", ScreenShot:=1, FindAll:=1
, JoinText:=0, offsetX:=20, offsetY:=10, dir:=1)
{
local
SetBatchLines, % (bch:=A_BatchLines)?"-1":"-1"
centerX:=Round(x1+x2)//2, centerY:=Round(y1+y2)//2
if (x1*x1+y1*y1+x2*x2+y2*y2<=0)
n:=150000, x:=y:=-n, w:=h:=2*n
else
x:=Min(x1,x2), y:=Min(y1,y2), w:=Abs(x2-x1)+1, h:=Abs(y2-y1)+1
bits:=this.GetBitsFromScreen(x,y,w,h,ScreenShot,zx,zy,zw,zh)
, info:=[]
Loop, Parse, text, |
if IsObject(j:=this.PicInfo(A_LoopField))
info.Push(j)
if (w<1 or h<1 or !(num:=info.MaxIndex()) or !bits.Scan0)
{
SetBatchLines, %bch%
return 0
}
arr:=[], in:={zx:zx, zy:zy, zw:zw, zh:zh
, sx:x-zx, sy:y-zy, sw:w, sh:h}, k:=0
For i,j in info
k:=Max(k, j.2*j.3), in.comment .= j.11
VarSetCapacity(s1, k*4), VarSetCapacity(s0, k*4)
, VarSetCapacity(gs, (w+2)*(h+2)), VarSetCapacity(ss, w*h)
, FindAll:=(dir=5 ? 1 : FindAll)
, JoinText:=(num=1 ? 0 : JoinText)
, allpos_max:=(FindAll or JoinText ? 10240 : 1)
, VarSetCapacity(allpos, allpos_max*8)
Loop, 2
{
if (err1=0 and err0=0) and (num>1 or A_Index>1)
err1:=0.05, err0:=0.05
Loop, % JoinText ? 1 : num
{
this.PicFind(arr, in, info, A_Index, err1, err0
, FindAll, JoinText, offsetX, offsetY, dir
, bits, gs, ss, s1, s0, allpos, allpos_max)
if (!FindAll and arr.MaxIndex())
Break
}
if (err1!=0 or err0!=0 or arr.MaxIndex()
or info.1.8=5 or info.1.12)
Break
}
if (dir=5)
arr:=this.Sort2(arr, centerX, centerY)
SetBatchLines, %bch%
return arr.MaxIndex() ? arr:0
}
PicFind(arr, in, info, index, err1, err0
, FindAll, JoinText, offsetX, offsetY, dir
, bits, ByRef gs, ByRef ss, ByRef s1, ByRef s0
, ByRef allpos, allpos_max)
{
local
static MyFunc:=""
if (!MyFunc)
{
x32:=""
. "5557565383EC408B44245483E80383E0FD0F84890100008B4424788B7424740F"
. "AF4424688B54247C8B4C24688B5C2454C1E60289742418F7DA01F08D349185DB"
. "89442428897424140F855A0300008B5424588B4C2458C744241000000000C744"
. "2418000000008B442428C1EA100FB6CD0FB6FA894C2408897C24040FB67C2458"
. "897C240C8B7C247C8D0CBD00000000894C24208B8C248000000085C90F8EA700"
. "00008B54247C85D20F8E810000008B7424648B6C241803AC248800000001C603"
. "4424208944241C0344246489042466900FB64E028B5C24040FB646010FB6162B"
. "4424082B54240C89CF01D929DF8D99000400000FAFC00FAFDFC1E00B0FAFDF01"
. "C3B8FE05000029C80FAFC20FAFD001D3395C245C0F93450083C60483C5013B34"
. "2475AD8B74247C017424188B44241C8344241001034424148B74241039B42480"
. "0000000F8559FFFFFF8B84249400000039842498000000C744240800000000C7"
. "042400000000C744241C0100000089C58B44247C0F4DAC24980000002B8424A4"
. "0000008944240C8B8424800000002B8424A800000089442414EB5D908D742600"
. "8B84249400000039842498000000C744241C0000000089C58B4424740F4DAC24"
. "980000000344247C2B8424A40000008944240C8B442478038424800000002B84"
. "24A8000000894424148B442478894424088B4424748904248B44246083E80283"
. "F8020F8723090000837C2460020F8420030000837C2460030F84530300008B44"
. "240CC744241800000000894424048B3C24397C24048B442408894424100F8CE2"
. "0200008B74241439742410C7442434040000000F8F85060000837C2454058B44"
. "24100F849E070000837C2454030F84200500000FAF44247C8B4C240485ED8D3C"
. "080F8E840000008BB4249C0000008B9C24A000000031C08B9424880000008B8C"
. "2494000000897C2428897424208BB4249800000001FA895C24248DB600000000"
. "39C17E1C8B9C248C0000008B3C8301D7803F00750B836C2420010F889F000000"
. "39C67E1C8B9C24900000008B3C8301D7803F00740B836C2424010F887F000000"
. "83C00139E875B98B7C24288B84249400000085C07E298B8C24940000008B8424"
. "8C0000008BB424880000008D1C888D0C3E8B1083C00401CA39C3C6020075F28B"
. "4C241C8B4424748B7C24188BB424AC0000000FAFC1034424048904FE8B442478"
. "0FAFC1034424108944FE0483C7013BBC24B0000000897C24180F8DA60100008B"
. "44243483F8010F847001000083F8020F847907000083F8030F847A0700008344"
. "241001E99BFEFFFF837C2454010F84FD010000837C2454020F84B20200008B54"
. "24588B4C24580FB65C2458C744240C00000000C744241C00000000C1EA100FB6"
. "F50FB6FA8B54245C89F8C1EA100FB6CA0FB654245C89CD8B4C245C29E8892C24"
. "89C589F00FB6CD29C88944240489D829D0894424108B042401F88904248D040E"
. "8B8C2480000000894424088D0413894424188B44247CC1E00285C9894424248B"
. "4424280F8E00FDFFFF8DB426000000008B54247C85D20F8E810000008B542464"
. "8B7C24648B4C241C038C248800000001C2034424248944242001C7EB368D7600"
. "391C247C3D394424047F37394424087C3189F00FB6F0397424100F9EC3397424"
. "180F9DC083C20483C10121D88841FF39D7741E0FB65A020FB642010FB63239DD"
. "7EBE31C083C20483C1018841FF39D775E28B7C247C017C241C8B442420834424"
. "0C01034424148B7C240C39BC24800000000F8559FFFFFFE94DFCFFFF83442404"
. "018B74240C397424040F8EF205000083442410018B742414397424108B042489"
. "4424047EDC8B44241883C4405B5E5F5DC260008B442414C74424180000000089"
. "4424108B4C2408394C24108B0424894424047CD18B74240C39742404C7442434"
. "020000000F8EEFFCFFFF836C241001EBD28B0424C74424180000000089442404"
. "8B74240C397424048B442408894424107F938B4C2414394C2410C74424340300"
. "00000F8EB1FCFFFF8344240401EBD1908B4424588BAC2480000000C704240000"
. "0000C7442404000000008D50018B44247CC1E207C1E00285ED89542458894424"
. "0C0F8E62FBFFFF8B4424288B6C2458908B7C247C85FF7E5F8B4C24648B5C2404"
. "8B7C2464039C248800000001C10344240C8944240801C789F68DBC2700000000"
. "0FB651020FB641010FB6316BC04B6BD22601C289F0C1E00429F001D039C50F97"
. "0383C10483C30139F975D58B4C247C014C24048B44240883042401034424148B"
. "342439B424800000007585E9D9FAFFFF8B4424740344247C8B4C247889442414"
. "8B4424788D71FF0384248000000089342439F00F8C4F0200008B4C247483C001"
. "C7442410000000008944241C8B44247C8D71FF8B0C240FAF4C246883C0028974"
. "24208944240C8B4424148D6801894C24088B442420394424140F8C960000008B"
. "0C248B5C24088B742410035C24182B742474035C2464C1E91F03B42484000000"
. "894C2404EB4F8D76008DBC27000000003944246C7E48807C24040075418B3C24"
. "397C24707E380FB64BFE83C3046BF9260FB64BF96BD14B8D0C170FB67BF889FA"
. "C1E20429FA01CAC1FA078854060183C00139E8741889C2C1EA1F84D274B2C644"
. "06010083C00183C30439E875E88B4C240C014C2410830424018B4C24688B0424"
. "014C24083944241C0F8543FFFFFFE9600100000FAF4424688B4C24048B742464"
. "8D048889F1894424240344245885ED0FB67C06020FB67406010FB60401897C24"
. "288974242C894424300F8E70FBFFFF8B8424A000000031FF896C24208944243C"
. "8B84249C00000089442438908D74260039BC24940000007E638B84248C000000"
. "8B5424248B7424280314B80FB65C11020FB64411012B44242C0FB614112B5424"
. "3089DD01F329F58DB3000400000FAFC00FAFF5C1E00B0FAFF501C6B8FE050000"
. "29D80FAFC20FAFD08D04163944245C730B836C2438010F88C602000039BC2498"
. "0000007E638B8424900000008B5424248B7424280314B80FB65C11020FB64411"
. "012B44242C0FB614112B54243089DD01F329F58DB3000400000FAFC00FAFF5C1"
. "E00B0FAFF501C6B8FE05000029D80FAFC20FAFD08D04163944245C720B836C24"
. "3C010F885A02000083C7013B7C24200F851BFFFFFF8B6C2420E961FAFFFF836C"
. "240401E946F9FFFF8B44247C83C0028944240C8BB4248000000085F60F8E47F8"
. "FFFF8B8424800000008B6C240C03AC2484000000C744240801000000C7442410"
. "0000000083C001894424148B44247C896C240483C004894424188B44245C6690"
. "8B5C247C85DB0F8E960000008B5424048B5C24108B742418039C248800000089"
. "D12B4C247C01D6890C248DB6000000000FB642010FB62ABF0100000003442458"
. "39E8723C0FB66A0239E872348B0C240FB669FF39E872290FB66EFF39E872210F"
. "B669FE39E872190FB62939E872120FB66EFE39E8720A0FB63E39F80F92C189CF"
. "89F98304240183C201880B83C60183C3018B3C24397C240475968B74247C0174"
. "241083442408018B7C240C8B742408017C2404397424140F8543FFFFFF894424"
. "5CE943F7FFFF0FAF4424688B7C240485ED8D34B80F8E25F9FFFF8B84248C0000"
. "008B088B8424900000008B0001F1894424588B4424640FB65424580FB6040829"
. "D03984249C0000000F8C31F9FFFF398424A00000000F8F24F9FFFF31D2896C24"
. "208B5C24588B7C2464EB36908D7426008B84248C0000008B0C908B8424900000"
. "0001F18B1C900FB6040F0FB6EB29E83B84249C0000007F5C3B8424A00000007C"
. "530FB6440F010FB6EF29E83984249C0000007C40398424A00000007F370FB644"
. "0F0289D9C1E9100FB6C929C83984249C0000007C1F398424A00000007F1683C2"
. "013B54242075898B6C2420895C2458E94BF8FFFF8B6C2420895C2458E97EF8FF"
. "FFC744243401000000E94BF7FFFF8344240401E93CFAFFFF8344241001E970FA"
. "FFFF8B6C2420E954F8FFFF8B442408C74424180000000089442410E9D4F9FFFF"
x64:=""
. "4157415641554154555756534883EC48448B9C24C0000000448BBC24E0000000"
. "89C8898C24900000008954242083E8034589C644898C24A800000083E0FD0F84"
. "700100008B8424D80000008BBC24D00000000FAF8424B8000000448D2CB88BBC"
. "24B80000004489F8F7D885C98D0487894424080F856A030000448B8C24E80000"
. "0089D789D3C1EB104889F8440FB6E20FB6DB0FB6EC4585C90F8ED2000000428D"
. "04BD00000000C7042400000000C744241000000000BFFE050000894424146690"
. "4585FF0F8E8E000000488BB424B00000004963C54531DB4C8D54060248637424"
. "104803B424F80000000F1F8000000000410FB652FE450FB60A410FB642FF4429"
. "E24489C94189D0428D140B29D929E8448D8A000400000FAFC0440FAFC9C1E00B"
. "440FAFC989F929D189CA410FAFD0418D0401410FAFD001D04139C6420F93041E"
. "4983C3014983C2044539DF7FA344036C241444017C24108304240144036C2408"
. "8B0424398424E80000000F8550FFFFFF8B84241001000039842418010000BE01"
. "0000004189C14489F8440F4D8C24180100002B84243001000031ED31FF890424"
. "8B8424E80000002B84243801000089442410EB578B8424100100003984241801"
. "00008BAC24D80000008BBC24D00000004189C18B8424D0000000440F4D8C2418"
. "01000031F64401F82B8424300100008904248B8424D8000000038424E8000000"
. "2B842438010000894424108B8424A800000083E80283F8020F875F0A000083BC"
. "24A8000000020F84FD02000083BC24A8000000030F8417030000448B1C244531"
. "ED4139FB4189EC0F8CC8020000443B642410C7442414040000000F8F44070000"
. "83BC2490000000050F846308000083BC2490000000030F845B0500004589E045"
. "0FAFC74501D84585C90F8EA900000044896C24088974241831C044895C242444"
. "8B9424280100008B9C2420010000488BB424F8000000448B9C2410010000448B"
. "AC2418010000897C2428660F1F4400004139C389C27E20488BBC24000100008B"
. "0C874401C14863C9803C0E00750983EB010F883E0900004139D57E21488BBC24"
. "080100008B14874401C24863D2803C1600740A4183EA010F88180900004883C0"
. "014139C17FAA448B6C24088B742418448B5C24248B7C24288B84241001000085"
. "C07E358B9C2410010000488B8424000100004C8B9424F80000008D53FF488D4C"
. "90048B104883C0044401C24839C84863D241C604120075EA438D442D00488B9C"
. "24400100004183C5014863D08B8424D00000000FAFC64401D88904938B8424D8"
. "0000000FAFC64401E0443BAC2448010000894493040F8D5A0100008B44241483"
. "F8010F843101000083F8020F845B08000083F8030F84720800004183C401E96A"
. "FEFFFF83BC2490000000010F848F01000083BC2490000000020F846D0200008B"
. "7C2420410FB6CE4589F141C1E91031ED4531E4450FB6C94889F8440FB6C74189"
. "FA0FB6D44489C74C89F029CF0FB6C489D641C1EA1029C6893C248D3C02418D04"
. "088B9424E8000000450FB6D24589D389C1428D04BD000000004529CB85D2438D"
. "1C0A894424100F8E04FDFFFF4489B424A00000004189CE660F1F840000000000"
. "4585FF0F8EC1010000488B8C24B00000004963C54D63D431D24C039424F80000"
. "00488D440102EB3B0F1F8400000000004439C37C4039CE7F3C39CF7C3844390C"
. "24410F9EC04539CE0F9DC14421C141880C124883C2014883C0044139D70F8E5F"
. "010000440FB6000FB648FF440FB648FE4539C37EBB31C9EBD54183C301443B1C"
. "240F8E180700004183C401443B6424104189FB7EE84489E84883C4485B5E5F5D"
. "415C415D415E415FC3448B6424104531ED4139EC4189FB7CDC443B1C24C74424"
. "14020000000F8E15FDFFFF4183EC01EBE04189FB4531ED443B1C244189EC7FB5"
. "443B642410C7442414030000000F8EEDFCFFFF4183C301EBDE0F1F8000000000"
. "8B542420448B8424E80000004531DB31DB428D34BD0000000083C201C1E20745"
. "85C0895424200F8EC4FBFFFF4489B424A00000008B6C24088B7C24204C8BB424"
. "B0000000448BA424E80000000F1F40004585FF7E544C63D34C039424F8000000"
. "4963C5498D4C06024531C00F1F4400000FB6110FB641FF440FB649FE6BC04B6B"
. "D22601C24489C8C1E0044429C801D039C7430F9704024983C0014883C1044539"
. "C77FCD4101F54401FB4183C3014101ED4539DC759B448BB424A0000000E92EFB"
. "FFFF44036C24104501FC83C50144036C240839AC24E80000000F8521FEFFFF44"
. "8BB424A0000000E904FBFFFF8B8424D00000008BBC24D80000004401F88D5FFF"
. "8904248B8424D8000000038424E800000039D80F8C140300008BBC24D0000000"
. "83C001448BAC24B8000000894424108BAC24C80000004489BC24E00000004489"
. "8424A000000083EF018D04BD00000000897C240831FF440FAFEB894424244898"
. "4889442418418D47024189FF894424148B0424448D5001660F1F840000000000"
. "8B4424083904240F8CA00000008B7C24244C8B7424184D63C74D63E54C038424"
. "F0000000418D543D0089DFC1EF1F4863D24989D14929D64C038C24B0000000EB"
. "4A4139C37E4E4084FF754939DD7E45410FB6490283C0014983C0016BF126410F"
. "B649016BD14B8D0C164B8D140E4983C104420FB6342289F2C1E20429F201CAC1"
. "FA07418850FF4139C2741D89C2C1EA1F84D274AD83C00141C600004983C10449"
. "83C0014139C275E344037C241483C3014403AC24B8000000395C24100F853EFF"
. "FFFF448BB424A0000000448BBC24E0000000E9DE0100008B8424B8000000488B"
. "9C24B00000004C8B9424B0000000410FAFC4428D049889C1034424204585C98D"
. "50024863D20FB61C138D50014898410FB604024863D2410FB61412895424080F"
. "8E53FBFFFF8B94242801000044896C24284531D2896C243C4489BC24E0000000"
. "89CD448BAC2410010000488B8C24B0000000895424248B942420010000448BBC"
. "241801000044896424344189C48974242C44895C243089542418897C24386690"
. "4539D54489D67E71488B842400010000428B149001EA8D42024898440FB60401"
. "8D42014863D20FB6141148980FB604014489C74101D82B442408458D98000400"
. "0029DF4429E2440FAFDF0FAFC0440FAFDFC1E00B4101C3B8FE0500004429C00F"
. "AFC20FAFD0418D04134139C6730B836C2418010F885C0300004139F77E71488B"
. "842408010000428B149001EA8D42024898440FB604018D42014863D20FB61411"
. "48980FB604014489C64101D82B442408458D980004000029DE4429E2440FAFDE"
. "0FAFC0440FAFDEC1E00B4101C3B8FE0500004429C00FAFC20FAFD0418D041341"
. "39C6720B836C2424010F88E60200004983C2014539D10F8F04FFFFFF448B6C24"
. "288B74242C448B5C2430448B6424348B7C24388B6C243C448BBC24E0000000E9"
. "D4F9FFFF4183EB01E994F8FFFF418D4702894424148B8C24E800000085C90F8E"
. "ACF7FFFF4863442414488BBC24F00000004D63E7498D6C2403BE0100000049F7"
. "D448896C24088B6C2420488D5C0701488904248B8424E800000031FF83C00189"
. "442410418D47FF4C8D68010F1F4400004585FF0F8EA2000000488B4424084863"
. "D748039424F8000000498D0C1C4D8D5C1D004C8D04184889D80F1F8000000000"
. "440FB630440FB648FF41BA010000004101EE4539CE7249440FB648014539CE72"
. "3F440FB649FF4539CE7235450FB648FF4539CE722B440FB649FE4539CE722144"
. "0FB6094539CE7218450FB648FE4539CE720E450FB6084539CE410F92C20F1F00"
. "4883C0014488124983C0014883C2014883C1014C39D875884401FF83C6014803"
. "1C24397424100F8544FFFFFFE99FF6FFFF8B8424B8000000410FAFC44585C946"
. "8D14980F8E8FF8FFFF488B9C2400010000488B8C24B00000008B03488B9C2408"
. "0100004401D08B1B4863D00FB614110FB6CB895C242029CA399424200100000F"
. "8C96F8FFFF399424280100000F8F89F8FFFF418D51FF44894C242431C944896C"
. "240889742418488D1C95000000004C8B8424B00000004989D98B5C2420EB4190"
. "488BB424000100008B440E04488BB424080100004401D08B5C0E044883C10448"
. "63D0410FB61410440FB6EB4429EA3B9424200100007F713B9424280100007C68"
. "8D50010FB6F74863D2410FB6141029F2399424200100007C4F39942428010000"
. "7F4683C00289DA4898C1EA10410FB604000FB6D229D0398424200100007C2939"
. "8424280100007F204939C90F856FFFFFFF448B6C24088B742418448B4C242489"
. "5C2420E970F7FFFF448B6C24088B742418448B4C2424895C2420E99CF7FFFFC7"
. "44241401000000E934F6FFFF4183C301E904F9FFFF448B6C24088B742418448B"
. "5C24248B7C2428E96FF7FFFF4183C401E90BF9FFFF448B6C24288B74242C448B"
. "5C2430448B6424348B7C24388B6C243C448BBC24E0000000E93EF7FFFF4189EC"
. "4531EDE983F8FFFF9090909090909090"
this.MCode(MyFunc, A_PtrSize=8 ? x64:x32)
}
num:=info.MaxIndex(), j:=info[index]
, text:=j.1, w:=j.2, h:=j.3, len1:=j.4, len0:=j.5
, e1:=(j.12 ? j.6 : Round(len1*err1))
, e0:=(j.12 ? j.7 : Round(len0*err0))
, mode:=j.8, color:=j.9, n:=j.10, comment:=j.11
, sx:=in.sx, sy:=in.sy, sw:=in.sw, sh:=in.sh, Stride:=bits.Stride
if (JoinText and index>1)
{
x:=in.x, y:=in.y, sw:=Min(x+offsetX+w,sx+sw), sx:=x, sw-=sx
, sh:=Min(y+offsetY+h,sy+sh), sy:=Max(y-offsetY,sy), sh-=sy
}
ListLines, % (lls:=A_ListLines)?"Off":"Off"
if (mode=5)
{
r:=StrSplit(text,"/"), i:=0, k:=-4
Loop, % n
NumPut(r[i+2]*Stride+r[i+1]*4, s1, k+=4, "int")
, NumPut(r[i+=3], s0, k, "int")
}
else
{
len1:=(e1>=len1 ? 0:len1), len0:=(e0>=len0 ? 0:len0)
if (mode=3)
j:=Stride-4*w+4, k:=4
, color:=(color//w)*Stride+Mod(color,w)*4
else
j:=sw-w+1, k:=1
i:=-j, k1:=k2:=-4
Loop, Parse, text
if (A_LoopField)
NumPut(i+=(Mod(A_Index-1,w)?k:j), s1, k1+=4, "int")
else
NumPut(i+=(Mod(A_Index-1,w)?k:j), s0, k2+=4, "int")
}
ListLines, %lls%
ok:=!bits.Scan0 ? 0:DllCall(&MyFunc
, "int",mode, "uint",color, "uint",n, "int",dir
, "Ptr",bits.Scan0, "int",Stride, "int",in.zw, "int",in.zh
, "int",sx, "int",sy, "int",sw, "int",sh
, "Ptr",&gs, "Ptr",&ss, "Ptr",&s1, "Ptr",&s0
, "int",len1, "int",len0, "int",e1, "int",e0
, "int",w, "int",h, "Ptr",&allpos, "int",allpos_max)
pos:=[]
Loop, % ok
pos.Push( NumGet(allpos, 8*A_Index-8, "uint")
, NumGet(allpos, 8*A_Index-4, "uint") )
Loop, % ok
{
x:=pos[2*A_Index-1], y:=pos[2*A_Index]
if (!JoinText)
{
x1:=x+in.zx, y1:=y+in.zy
, arr.Push( {1:x1, 2:y1, 3:w, 4:h
, x:x1+w//2, y:y1+h//2, id:comment} )
}
else if (index=1)
{
in.x:=x+w, in.y:=y, in.minY:=y, in.maxY:=y+h
Loop, % num-1
if !this.PicFind(arr, in, info, A_Index+1, err1, err0
, FindAll, JoinText, offsetX, offsetY, 3
, bits, gs, ss, s1, s0, allpos, 1)
Continue, 2
x1:=x+in.zx, y1:=in.minY+in.zy
, w1:=in.x-x, h1:=in.maxY-in.minY
, arr.Push( {1:x1, 2:y1, 3:w1, 4:h1
, x:x1+w1//2, y:y1+h1//2, id:in.comment} )
}
else
{
in.x:=x+w, in.y:=y
, (y<in.minY && in.minY:=y)
, (y+h>in.maxY && in.maxY:=y+h)
return 1
}
if (!FindAll and arr.MaxIndex())
return
}
}
GetBitsFromScreen(ByRef x, ByRef y, ByRef w, ByRef h
, ScreenShot:=1, ByRef zx:="", ByRef zy:=""
, ByRef zw:="", ByRef zh:="")
{
local
static Ptr:="Ptr"
bits:=this.bits
if (!ScreenShot)
{
zx:=bits.zx, zy:=bits.zy, zw:=bits.zw, zh:=bits.zh
if IsByRef(x)
w:=Min(x+w,zx+zw), x:=Max(x,zx), w-=x
, h:=Min(y+h,zy+zh), y:=Max(y,zy), h-=y
return bits
}
bch:=A_BatchLines, cri:=A_IsCritical
Critical
if (id:=this.BindWindow(0,0,1))
{
WinGet, id, ID, ahk_id %id%
WinGetPos, zx, zy, zw, zh, ahk_id %id%
}
if (!id)
{
SysGet, zx, 76
SysGet, zy, 77
SysGet, zw, 78
SysGet, zh, 79
}
bits.zx:=zx, bits.zy:=zy, bits.zw:=zw, bits.zh:=zh
, w:=Min(x+w,zx+zw), x:=Max(x,zx), w-=x
, h:=Min(y+h,zy+zh), y:=Max(y,zy), h-=y
if (zw>bits.oldzw or zh>bits.oldzh or !bits.hBM)
{
hBM:=bits.hBM
, VarSetCapacity(bi, 40, 0), NumPut(40, bi, 0, "int")
, NumPut(zw, bi, 4, "int"), NumPut(-zh, bi, 8, "int")
, NumPut(1, bi, 12, "short"), NumPut(bpp:=32, bi, 14, "short")
, bits.hBM:=DllCall("CreateDIBSection", Ptr,0, Ptr,&bi
, "int",0, "Ptr*",ppvBits:=0, Ptr,0, "int",0, Ptr)
, bits.Scan0:=(!bits.hBM ? 0:ppvBits)
, bits.Stride:=((zw*bpp+31)//32)*4
, bits.oldzw:=zw, bits.oldzh:=zh
, DllCall("DeleteObject", Ptr,hBM)
}
if (bits.hBM) and !(w<1 or h<1)
{
mDC:=DllCall("CreateCompatibleDC", Ptr,0, Ptr)
oBM:=DllCall("SelectObject", Ptr,mDC, Ptr,bits.hBM, Ptr)
if (id)
{
if (mode:=this.BindWindow(0,0,0,1))<2
{
hDC2:=DllCall("GetDCEx", Ptr,id, Ptr,0, "int",3, Ptr)
DllCall("BitBlt",Ptr,mDC,"int",x-zx,"int",y-zy,"int",w,"int",h
, Ptr,hDC2, "int",x-zx, "int",y-zy, "uint",0x00CC0020|0x40000000)
DllCall("ReleaseDC", Ptr,id, Ptr,hDC2)
}
else
{
VarSetCapacity(bi, 40, 0), NumPut(40, bi, 0, "int")
NumPut(zw, bi, 4, "int"), NumPut(-zh, bi, 8, "int")
NumPut(1, bi, 12, "short"), NumPut(32, bi, 14, "short")
hBM2:=DllCall("CreateDIBSection", Ptr,0, Ptr,&bi
, "int",0, "Ptr*",0, Ptr,0, "int",0, Ptr)
mDC2:=DllCall("CreateCompatibleDC", Ptr,0, Ptr)
oBM2:=DllCall("SelectObject", Ptr,mDC2, Ptr,hBM2, Ptr)
DllCall("PrintWindow", Ptr,id, Ptr,mDC2, "uint",(mode>3)*3)
DllCall("BitBlt",Ptr,mDC,"int",x-zx,"int",y-zy,"int",w,"int",h
, Ptr,mDC2, "int",x-zx, "int",y-zy, "uint",0x00CC0020|0x40000000)
DllCall("SelectObject", Ptr,mDC2, Ptr,oBM2)
DllCall("DeleteDC", Ptr,mDC2)
DllCall("DeleteObject", Ptr,hBM2)
}
}
else
{
win:=DllCall("GetDesktopWindow", Ptr)
hDC:=DllCall("GetWindowDC", Ptr,win, Ptr)
DllCall("BitBlt",Ptr,mDC,"int",x-zx,"int",y-zy,"int",w,"int",h
, Ptr,hDC, "int",x, "int",y, "uint",0x00CC0020|0x40000000)
DllCall("ReleaseDC", Ptr,win, Ptr,hDC)
}
DllCall("SelectObject", Ptr,mDC, Ptr,oBM)
DllCall("DeleteDC", Ptr,mDC)
}
Critical, %cri%
SetBatchLines, %bch%
return bits
}
PicInfo(text)
{
local
static info:=[]
if !InStr(text,"$")
return
if (info[text])
return info[text]
v:=text, comment:="", seterr:=e1:=e0:=0
; You Can Add Comment Text within The <>
if RegExMatch(v,"<([^>]*)>",r)
v:=StrReplace(v,r), comment:=Trim(r1)
; You can Add two fault-tolerant in the [], separated by commas
if RegExMatch(v,"\[([^\]]*)]",r)
{
v:=StrReplace(v,r), r:=StrSplit(r1, ",")
, seterr:=1, e1:=r.1, e0:=r.2
}
r:=StrSplit(v,"$"), color:=r.1, v:=r.2
mode:=InStr(color,"##") ? 5
: InStr(color,"-") ? 4 : InStr(color,"#") ? 3
: InStr(color,"**") ? 2 : InStr(color,"*") ? 1 : 0
color:=RegExReplace(color,"[*#]")
if (mode=5)
{
v:=Trim(StrReplace(RegExReplace(v,"\s"),",","/"),"/")
r:=StrSplit(v,"/"), n:=r.MaxIndex()//3
if (!n)
return
v:="", x1:=x2:=r.1, y1:=y2:=r.2, i:=j:=1
Loop, % n
x:=r[i++], y:=r[i++], i++
, (x<x1 && x1:=x), (x>x2 && x2:=x)
, (y<y1 && y1:=y), (y>y2 && y2:=y)
Loop, % n
v.="/" (r[j++]-x1) "/" (r[j++]-y1) "/"
. Floor("0x" r[j++])&0xFFFFFF
v:=SubStr(v,2), w:=x2-x1+1, h:=y2-y1+1
, len1:=len0:=n, seterr:=1, e1:=color, e0:=-color
}
else
{
r:=StrSplit(v,"."), w:=r.1
, v:=this.base64tobit(r.2), h:=StrLen(v)//w
if (w<1 or h<1 or StrLen(v)!=w*h)
return
if (mode=4)
{
r:=StrSplit(StrReplace(color,"0x"),"-")
, color:=Round("0x" r.1), n:=Round("0x" r.2)
}
else
{
r:=StrSplit(color,"@")
, color:=r.1, n:=Round(r.2,2)+(!r.2)
, n:=Floor(512*9*255*255*(1-n)*(1-n))
}
StrReplace(v,"1","",len1), len0:=StrLen(v)-len1
, e1:=Round(len1*e1), e0:=Round(len0*e0)
}
return info[text]:=[v,w,h,len1,len0,e1,e0
, mode,color,n,comment,seterr]
}
; Bind the window so that it can find images when obscured
; by other windows, it's equivalent to always being
; at the front desk. Unbind Window using FindText.BindWindow(0)
BindWindow(bind_id:=0, bind_mode:=0, get_id:=0, get_mode:=0)
{
local
bind:=this.bind
if (get_id)
return bind.id
if (get_mode)
return bind.mode
if (bind_id)
{
bind.id:=bind_id, bind.mode:=bind_mode, bind.oldStyle:=0
if (bind_mode & 1)
{
WinGet, oldStyle, ExStyle, ahk_id %bind_id%
bind.oldStyle:=oldStyle
WinSet, Transparent, 255, ahk_id %bind_id%
Loop, 30
{
Sleep, 100
WinGet, i, Transparent, ahk_id %bind_id%
}
Until (i=255)
}
}
else
{
bind_id:=bind.id
if (bind.mode & 1)
WinSet, ExStyle, % bind.oldStyle, ahk_id %bind_id%
bind.id:=0, bind.mode:=0, bind.oldStyle:=0
}
}
MCode(ByRef code, hex)
{
local
ListLines, % (lls:=A_ListLines)?"Off":"Off"
SetBatchLines, % (bch:=A_BatchLines)?"-1":"-1"
VarSetCapacity(code, len:=StrLen(hex)//2)
Loop, % len
NumPut("0x" SubStr(hex,2*A_Index-1,2),code,A_Index-1,"uchar")
DllCall("VirtualProtect","Ptr",&code,"Ptr",len,"uint",0x40,"Ptr*",0)
SetBatchLines, %bch%
ListLines, %lls%
}
base64tobit(s)
{
local
Chars:="0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZ"
. "abcdefghijklmnopqrstuvwxyz"
ListLines, % (lls:=A_ListLines)?"Off":"Off"
Loop, Parse, Chars
{
i:=A_Index-1, v:=(i>>5&1) . (i>>4&1)
. (i>>3&1) . (i>>2&1) . (i>>1&1) . (i&1)
s:=RegExReplace(s,"[" A_LoopField "]",StrReplace(v,"0x"))
}
ListLines, %lls%
return RegExReplace(RegExReplace(s,"10*$"),"[^01]+")
}
bit2base64(s)
{
local
s:=RegExReplace(s,"[^01]+")
s.=SubStr("100000",1,6-Mod(StrLen(s),6))
s:=RegExReplace(s,".{6}","|$0")
Chars:="0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZ"
. "abcdefghijklmnopqrstuvwxyz"
ListLines, % (lls:=A_ListLines)?"Off":"Off"
Loop, Parse, Chars
{
i:=A_Index-1, v:="|" . (i>>5&1) . (i>>4&1)
. (i>>3&1) . (i>>2&1) . (i>>1&1) . (i&1)
s:=StrReplace(s,StrReplace(v,"0x"),A_LoopField)
}
ListLines, %lls%
return s
}
xywh2xywh(x1,y1,w1,h1, ByRef x, ByRef y, ByRef w, ByRef h
, ByRef zx:="", ByRef zy:="", ByRef zw:="", ByRef zh:="")
{
local
SysGet, zx, 76
SysGet, zy, 77
SysGet, zw, 78
SysGet, zh, 79
w:=Min(x1+w1,zx+zw), x:=Max(x1,zx), w-=x
, h:=Min(y1+h1,zy+zh), y:=Max(y1,zy), h-=y
}
ASCII(s)
{
local
if RegExMatch(s,"\$(\d+)\.([\w+/]+)",r)
{
s:=RegExReplace(this.base64tobit(r2),".{" r1 "}","$0`n")
s:=StrReplace(StrReplace(s,"0","_"),"1","0")
}
else s=
return s
}
; You can put the text library at the beginning of the script,
; and Use FindText.PicLib(Text,1) to add the text library to PicLib()'s Lib,
; Use FindText.PicLib("comment1|comment2|...") to get text images from Lib
PicLib(comments, add_to_Lib:=0, index:=1)
{
local
Lib:=this.Lib
if (add_to_Lib)
{
re:="<([^>]*)>[^$]+\$\d+\.[\w+/]+"
Loop, Parse, comments, |
if RegExMatch(A_LoopField,re,r)
{
s1:=Trim(r1), s2:=""
Loop, Parse, s1
s2.="_" . Format("{:d}",Ord(A_LoopField))
Lib[index,s2]:=r
}
Lib[index,""]:=""
}
else
{
Text:=""
Loop, Parse, comments, |
{
s1:=Trim(A_LoopField), s2:=""
Loop, Parse, s1
s2.="_" . Format("{:d}",Ord(A_LoopField))
Text.="|" . Lib[index,s2]
}
return Text
}
}
; Decompose a string into individual characters and get their data
PicN(Number, index:=1)
{
return this.PicLib(RegExReplace(Number,".","|$0"), 0, index)
}
; Use FindText.PicX(Text) to automatically cut into multiple characters
; Can't be used in ColorPos mode, because it can cause position errors
PicX(Text)
{
local
if !RegExMatch(Text,"(<[^$]+)\$(\d+)\.([\w+/]+)",r)
return Text
v:=this.base64tobit(r3), Text:=""
c:=StrLen(StrReplace(v,"0"))<=StrLen(v)//2 ? "1":"0"
txt:=RegExReplace(v,".{" r2 "}","$0`n")
While InStr(txt,c)
{
While !(txt~="m`n)^" c)
txt:=RegExReplace(txt,"m`n)^.")
i:=0
While (txt~="m`n)^.{" i "}" c)
i:=Format("{:d}",i+1)
v:=RegExReplace(txt,"m`n)^(.{" i "}).*","$1")
txt:=RegExReplace(txt,"m`n)^.{" i "}")
if (v!="")
Text.="|" r1 "$" i "." this.bit2base64(v)
}
return Text
}
; Screenshot and retained as the last screenshot.
ScreenShot(x1:=0, y1:=0, x2:=0, y2:=0)
{
this.FindText(x1, y1, x2, y2)
}
; Get the RGB color of a point from the last screenshot.
; If the point to get the color is beyond the range of
; Screen, it will return White color (0xFFFFFF).
GetColor(x, y, fmt:=1)
{
local
bits:=this.GetBitsFromScreen(0,0,0,0,0,zx,zy,zw,zh)
, c:=(x<zx or x>=zx+zw or y<zy or y>=zy+zh or !bits.Scan0)
? 0xFFFFFF : NumGet(bits.Scan0+(y-zy)*bits.Stride+(x-zx)*4,"uint")
return (fmt ? Format("0x{:06X}",c&0xFFFFFF) : c)
}
; Identify a line of text or verification code
; based on the result returned by FindText().
; offsetX is the maximum interval between two texts,
; if it exceeds, a "*" sign will be inserted.
; offsetY is the maximum height difference between two texts.
; Return Association array {ocr:Text, x:X, y:Y, w:W, h:H}
Ocr(ok, offsetX:=20, offsetY:=20)
{
local
ocr_Text:=ocr_X:=ocr_Y:=min_X:=""
For k,v in ok
x:=v.1
, min_X:=(A_Index=1 or x<min_X ? x : min_X)
, max_X:=(A_Index=1 or x>max_X ? x : max_X)
While (min_X!="" and min_X<=max_X)
{
LeftX:=""
For k,v in ok
{
x:=v.1, y:=v.2
if (x<min_X) or Abs(y-ocr_Y)>offsetY
Continue
; Get the leftmost X coordinates
if (LeftX="" or x<LeftX)
LeftX:=x, LeftY:=y, LeftW:=v.3, LeftH:=v.4, LeftOCR:=v.id
}
if (LeftX="")
Break
if (ocr_X="")
ocr_X:=LeftX, min_Y:=LeftY, max_Y:=LeftY+LeftH
; If the interval exceeds the set value, add "*" to the result
ocr_Text.=(ocr_Text!="" and LeftX-min_X>offsetX ? "*":"") . LeftOCR
; Update for next search
min_X:=LeftX+LeftW, ocr_Y:=LeftY
, (LeftY<min_Y && min_Y:=LeftY)
, (LeftY+LeftH>max_Y && max_Y:=LeftY+LeftH)
}
return {ocr:ocr_Text, x:ocr_X, y:min_Y
, w: min_X-ocr_X, h: max_Y-min_Y}
}
; Sort the results returned by FindText() from left to right
; and top to bottom, ignore slight height difference
Sort(ok, dy:=10)
{
local
if !IsObject(ok)
return ok
ypos:=[]
For k,v in ok
{
x:=v.x, y:=v.y, add:=1
For k2,v2 in ypos
if Abs(y-v2)<=dy
{
y:=v2, add:=0
Break
}
if (add)
ypos.Push(y)
n:=(y*150000+x) "." k, s:=A_Index=1 ? n : s "-" n
}
Sort, s, N D-
ok2:=[]
Loop, Parse, s, -
ok2.Push( ok[(StrSplit(A_LoopField,".")[2])] )
return ok2
}
; Reordering according to the nearest distance
Sort2(ok, px, py)
{
local
if !IsObject(ok)
return ok
For k,v in ok
n:=((v.x-px)**2+(v.y-py)**2) "." k, s:=A_Index=1 ? n : s "-" n
Sort, s, N D-
ok2:=[]
Loop, Parse, s, -
ok2.Push( ok[(StrSplit(A_LoopField,".")[2])] )
return ok2
}
; Prompt mouse position in remote assistance
MouseTip(x:="", y:="", w:=10, h:=10, d:=4)
{
local
if (x="")
{
VarSetCapacity(pt,16,0), DllCall("GetCursorPos","ptr",&pt)
x:=NumGet(pt,0,"uint"), y:=NumGet(pt,4,"uint")
}
x:=Round(x-w-d), y:=Round(y-h-d), w:=(2*w+1)+2*d, h:=(2*h+1)+2*d
;-------------------------
Gui, _MouseTip_: +AlwaysOnTop -Caption +ToolWindow +Hwndmyid -DPIScale
Gui, _MouseTip_: Show, Hide w%w% h%h%
;-------------------------
DetectHiddenWindows, % (dhw:=A_DetectHiddenWindows)?"On":"On"
i:=w-d, j:=h-d
s=0-0 %w%-0 %w%-%h% 0-%h% 0-0 %d%-%d% %i%-%d% %i%-%j% %d%-%j% %d%-%d%
WinSet, Region, %s%, ahk_id %myid%
DetectHiddenWindows, %dhw%
;-------------------------
Gui, _MouseTip_: Show, NA x%x% y%y%
Loop, 4
{
Gui, _MouseTip_: Color, % A_Index & 1 ? "Red" : "Blue"
Sleep, 500
}
Gui, _MouseTip_: Destroy
}
; Quickly get the search data of screen image
GetTextFromScreen(x1, y1, x2, y2, Threshold:=""
, ScreenShot:=1, ByRef rx:="", ByRef ry:="")
{
local
SetBatchLines, % (bch:=A_BatchLines)?"-1":"-1"
x:=Min(x1,x2), y:=Min(y1,y2), w:=Abs(x2-x1)+1, h:=Abs(y2-y1)+1
this.GetBitsFromScreen(x,y,w,h,ScreenShot,zx,zy,zw,zh)
if (w<1 or h<1)
{
SetBatchLines, %bch%
return
}
ListLines, % (lls:=A_ListLines)?"Off":"Off"
gs:=[], k:=0
Loop, %h%
{
j:=y+A_Index-1
Loop, %w%
i:=x+A_Index-1, c:=this.GetColor(i,j,0)
, gs[++k]:=(((c>>16)&0xFF)*38+((c>>8)&0xFF)*75+(c&0xFF)*15)>>7
}
if InStr(Threshold,"**")
{
Threshold:=StrReplace(Threshold,"*")
if (Threshold="")
Threshold:=50
s:="", sw:=w, w-=2, h-=2, x++, y++
Loop, %h%
{
y1:=A_Index
Loop, %w%
x1:=A_Index, i:=y1*sw+x1+1, j:=gs[i]+Threshold
, s.=( gs[i-1]>j || gs[i+1]>j
|| gs[i-sw]>j || gs[i+sw]>j
|| gs[i-sw-1]>j || gs[i-sw+1]>j
|| gs[i+sw-1]>j || gs[i+sw+1]>j ) ? "1":"0"
}
Threshold:="**" Threshold
}
else
{
Threshold:=StrReplace(Threshold,"*")
if (Threshold="")
{
pp:=[]
Loop, 256
pp[A_Index-1]:=0
Loop, % w*h
pp[gs[A_Index]]++
IP:=IS:=0
Loop, 256
k:=A_Index-1, IP+=k*pp[k], IS+=pp[k]
Threshold:=Floor(IP/IS)
Loop, 20
{
LastThreshold:=Threshold
IP1:=IS1:=0
Loop, % LastThreshold+1
k:=A_Index-1, IP1+=k*pp[k], IS1+=pp[k]
IP2:=IP-IP1, IS2:=IS-IS1
if (IS1!=0 and IS2!=0)
Threshold:=Floor((IP1/IS1+IP2/IS2)/2)
if (Threshold=LastThreshold)
Break
}
}
s:=""
Loop, % w*h
s.=gs[A_Index]<=Threshold ? "1":"0"
Threshold:="*" Threshold
}
;--------------------
w:=Format("{:d}",w), CutUp:=CutDown:=0
re1=(^0{%w%}|^1{%w%})
re2=(0{%w%}$|1{%w%}$)
While RegExMatch(s,re1)
s:=RegExReplace(s,re1), CutUp++
While RegExMatch(s,re2)
s:=RegExReplace(s,re2), CutDown++
rx:=x+w//2, ry:=y+CutUp+(h-CutUp-CutDown)//2
s:="|<>" Threshold "$" w "." this.bit2base64(s)
;--------------------
SetBatchLines, %bch%
ListLines, %lls%
return s
}
; Quickly save screen image to BMP file for debugging
SavePic(file, x1:=0, y1:=0, x2:=0, y2:=0, ScreenShot:=1)
{
local
static Ptr:="Ptr"
SetBatchLines, % (bch:=A_BatchLines)?"-1":"-1"
if (x1*x1+y1*y1+x2*x2+y2*y2<=0)
n:=150000, x:=y:=-n, w:=h:=2*n
else
x:=Min(x1,x2), y:=Min(y1,y2), w:=Abs(x2-x1)+1, h:=Abs(y2-y1)+1
bits:=this.GetBitsFromScreen(x,y,w,h,ScreenShot,zx,zy,zw,zh)
if (w<1 or h<1 or !bits.hBM)
{
SetBatchLines, %bch%
return
}
VarSetCapacity(bi, 40, 0), NumPut(40, bi, 0, "int")
NumPut(w, bi, 4, "int"), NumPut(h, bi, 8, "int")
NumPut(1, bi, 12, "short"), NumPut(bpp:=24, bi, 14, "short")
hBM:=DllCall("CreateDIBSection", Ptr,0, Ptr,&bi
, "int",0, "Ptr*",ppvBits:=0, Ptr,0, "int",0, Ptr)
mDC:=DllCall("CreateCompatibleDC", Ptr,0, Ptr)
oBM:=DllCall("SelectObject", Ptr,mDC, Ptr,hBM, Ptr)
;-------------------------
mDC2:=DllCall("CreateCompatibleDC", Ptr,0, Ptr)
oBM2:=DllCall("SelectObject", Ptr,mDC2, Ptr,bits.hBM, Ptr)
DllCall("BitBlt",Ptr,mDC,"int",0,"int",0,"int",w,"int",h
, Ptr,mDC2, "int",x-zx, "int",y-zy, "uint",0x00CC0020)
DllCall("SelectObject", Ptr,mDC2, Ptr,oBM2)
DllCall("DeleteDC", Ptr,mDC2)
;-------------------------
size:=((w*bpp+31)//32)*4*h
VarSetCapacity(bf, 14, 0), StrPut("BM", &bf, "CP0")
NumPut(54+size, bf, 2, "uint"), NumPut(54, bf, 10, "uint")
f:=FileOpen(file,"w"), f.RawWrite(bf,14), f.RawWrite(bi,40)
, f.RawWrite(ppvBits+0, size), f.Close()
;-------------------------
DllCall("SelectObject", Ptr,mDC, Ptr,oBM)
DllCall("DeleteDC", Ptr,mDC)
DllCall("DeleteObject", Ptr,hBM)
SetBatchLines, %bch%
}
; Show the last screen shot
ShowScreenShot(onoff:=1)
{
local
static Ptr:="Ptr"
Gui, FindText_Screen: Destroy
bits:=this.GetBitsFromScreen(0,0,0,0,0,zx,zy,zw,zh)
if (!onoff or !bits.hBM or zw<1 or zh<1)
return
mDC:=DllCall("CreateCompatibleDC", Ptr,0, Ptr)
oBM:=DllCall("SelectObject", Ptr,mDC, Ptr,bits.hBM, Ptr)
hBrush:=DllCall("CreateSolidBrush", "uint",0xFFFFFF, Ptr)
oBrush:=DllCall("SelectObject", Ptr,mDC, Ptr,hBrush, Ptr)
DllCall("BitBlt", Ptr,mDC, "int",0, "int",0, "int",zw, "int",zh
, Ptr,mDC, "int",0, "int",0, "uint",0xC000CA) ; MERGECOPY
DllCall("SelectObject", Ptr,mDC, Ptr,oBrush)
DllCall("DeleteObject", Ptr,hBrush)
DllCall("SelectObject", Ptr,mDC, Ptr,oBM)
DllCall("DeleteDC", Ptr,mDC)
;---------------------
Gui, FindText_Screen: +AlwaysOnTop -Caption +ToolWindow -DPIScale +E0x08000000
Gui, FindText_Screen: Margin, 0, 0
Gui, FindText_Screen: Add, Picture, x0 y0 w%zw% h%zh% +Hwndid +0xE
SendMessage, 0x172, 0, bits.hBM,, ahk_id %id%
Gui, FindText_Screen: Show, NA x%zx% y%zy% w%zw% h%zh%, Show ScreenShot
}
; Running AHK code dynamically with new threads
Class Thread
{
__New(args*)
{
this.pid:=this.Exec(args*)
}
__Delete()
{
Process, Close, % this.pid
}
Exec(s, Ahk:="", args:="")
{
local
Ahk:=Ahk ? Ahk:A_IsCompiled ? A_ScriptDir "\AutoHotkey.exe":A_AhkPath
s:="DllCall(""SetWindowText"",""Ptr"",A_ScriptHwnd,""Str"",""<AHK>"")`n"
. StrReplace(s,"`r"), pid:=""
Try
{
shell:=ComObjCreate("WScript.Shell")
oExec:=shell.Exec("""" Ahk """ /f * " args)
oExec.StdIn.Write(s)
oExec.StdIn.Close(), pid:=oExec.ProcessID
}
Catch
{
f:=A_Temp "\~ahk.tmp"
s:="`n FileDelete, " f "`n" s
FileDelete, %f%
FileAppend, %s%, %f%
r:=ObjBindMethod(this, "Clear")
SetTimer, %r%, -3000
Run, "%Ahk%" /f "%f%" %args%,, UseErrorLevel, pid
}
return pid
}
Clear()
{
FileDelete, % A_Temp "\~ahk.tmp"
SetTimer,, Off
}
}
WindowToScreen(ByRef x, ByRef y, id:="")
{
WinGetPos, winx, winy,,, % id ? "ahk_id " id : "A"
x+=Floor(winx), y+=Floor(winy)
}
ScreenToWindow(ByRef x, ByRef y, id:="")
{
this.WindowToScreen(dx:=0, dy:=0, id), x-=dx, y-=dy
}
ClientToScreen(ByRef x, ByRef y, id:="")
{
if (!id)
WinGet, id, ID, A
VarSetCapacity(pt,8,0), NumPut(0,pt,"int64")
, DllCall("ClientToScreen","Ptr",id,"Ptr",&pt)
, x+=NumGet(pt,"int"), y+=NumGet(pt,4,"int")
}
ScreenToClient(ByRef x, ByRef y, id:="")
{
this.ClientToScreen(dx:=0, dy:=0, id), x-=dx, y-=dy
}
/***** C source code of machine code *****
int __attribute__((__stdcall__)) PicFind(
int mode, unsigned int c, unsigned int n, int dir
, unsigned char * Bmp, int Stride, int zw, int zh
, int sx, int sy, int sw, int sh
, unsigned char * gs, char * ss, int * s1, int * s0
, int len1, int len0, int err1, int err0
, int w, int h, unsigned int * allpos, int allpos_max )
{
int ok=0, o, i, j, k, v, r, g, b, rr, gg, bb;
int x, y, x1, y1, x2, y2, e1, e0, max;
int r_min, r_max, g_min, g_max, b_min, b_max;
//----------------------
// MultiColor Mode
if (mode==5) goto StartLookUp;
//----------------------
// Color Position Mode
// only used to recognize multicolored Verification Code
if (mode==3) goto StartLookUp;
//----------------------
// Generate Two Value Image
o=sy*Stride+sx*4; j=Stride-sw*4; i=0;
if (mode==0) // Color Mode
{
rr=(c>>16)&0xFF; gg=(c>>8)&0xFF; bb=c&0xFF;
for (y=0; y<sh; y++, o+=j)
for (x=0; x<sw; x++, o+=4, i++)
{
r=Bmp[2+o]-rr; g=Bmp[1+o]-gg; b=Bmp[o]-bb; v=r+rr+rr;
ss[i]=((1024+v)*r*r+2048*g*g+(1534-v)*b*b<=n) ? 1:0;
}
}
else if (mode==1) // Gray Threshold Mode
{
c=(c+1)<<7;
for (y=0; y<sh; y++, o+=j)
for (x=0; x<sw; x++, o+=4, i++)
ss[i]=(Bmp[2+o]*38+Bmp[1+o]*75+Bmp[o]*15<c) ? 1:0;
}
else if (mode==2) // Gray Difference Mode
{
x2=sx+sw; y2=sy+sh;
for (y=sy-1; y<=y2; y++)
{
for (x=sx-1; x<=x2; x++, i++)
if (x<0 || x>=zw || y<0 || y>=zh)
gs[i]=0;
else
{
o=y*Stride+x*4;
gs[i]=(Bmp[2+o]*38+Bmp[1+o]*75+Bmp[o]*15)>>7;
}
}
k=sw+2; i=0;
for (y=1; y<=sh; y++)
for (x=1; x<=sw; x++, i++)
{
o=y*k+x; n=gs[o]+c;
ss[i]=(gs[o-1]>n || gs[o+1]>n
|| gs[o-k]>n || gs[o+k]>n
|| gs[o-k-1]>n || gs[o-k+1]>n
|| gs[o+k-1]>n || gs[o+k+1]>n) ? 1:0;
}
}
else // (mode==4) Color Difference Mode
{
r=(c>>16)&0xFF; g=(c>>8)&0xFF; b=c&0xFF;
rr=(n>>16)&0xFF; gg=(n>>8)&0xFF; bb=n&0xFF;
r_min=r-rr; g_min=g-gg; b_min=b-bb;
r_max=r+rr; g_max=g+gg; b_max=b+bb;
for (y=0; y<sh; y++, o+=j)
for (x=0; x<sw; x++, o+=4, i++)
{
r=Bmp[2+o]; g=Bmp[1+o]; b=Bmp[o];
ss[i]=(r>=r_min && r<=r_max
&& g>=g_min && g<=g_max
&& b>=b_min && b<=b_max) ? 1:0;
}
}
//----------------------
StartLookUp:
max=(len1>len0) ? len1 : len0;
if (mode==5 || mode==3)
{ x1=sx; y1=sy; x2=sx+sw-w; y2=sy+sh-h; k=0; }
else
{ x1=0; y1=0; x2=sw-w; y2=sh-h; k=1; }
if (dir<1 || dir>4) dir=1;
if (dir==1) // From top to bottom
{
for (y=y1; y<=y2; y++)
{
for (x=x1; x<=x2; x++)
{
goto GoSub;
GoBack1:;
}
}
}
else if (dir==2) // From bottom to top
{
for (y=y2; y>=y1; y--)
{
for (x=x1; x<=x2; x++)
{
goto GoSub;
GoBack2:;
}
}
}
else if (dir==3) // From left to right
{
for (x=x1; x<=x2; x++)
{
for (y=y1; y<=y2; y++)
{
goto GoSub;
GoBack3:;
}
}
}
else // (dir==4) From right to left
{
for (x=x2; x>=x1; x--)
{
for (y=y1; y<=y2; y++)
{
goto GoSub;
GoBack4:;
}
}
}
goto Return1;
//----------------------
GoSub:
if (mode==5)
{
o=y*Stride+x*4;
for (i=0; i<max; i++)
{
j=o+s1[i]; c=s0[i];
b=Bmp[j]-(c&0xFF); if (b>err1 || b<err0) goto NoMatch;
g=Bmp[1+j]-((c>>8)&0xFF); if (g>err1 || g<err0) goto NoMatch;
r=Bmp[2+j]-((c>>16)&0xFF); if (r>err1 || r<err0) goto NoMatch;
}
}
else if (mode==3)
{
o=y*Stride+x*4; e1=err1; e0=err0;
j=o+c; rr=Bmp[2+j]; gg=Bmp[1+j]; bb=Bmp[j];
for (i=0; i<max; i++)
{
if (i<len1)
{
j=o+s1[i]; r=Bmp[2+j]-rr; g=Bmp[1+j]-gg; b=Bmp[j]-bb; v=r+rr+rr;
if ((1024+v)*r*r+2048*g*g+(1534-v)*b*b>n && (--e1)<0)
goto NoMatch;
}
if (i<len0)
{
j=o+s0[i]; r=Bmp[2+j]-rr; g=Bmp[1+j]-gg; b=Bmp[j]-bb; v=r+rr+rr;
if ((1024+v)*r*r+2048*g*g+(1534-v)*b*b<=n && (--e0)<0)
goto NoMatch;
}
}
}
else
{
o=y*sw+x; e1=err1; e0=err0;
for (i=0; i<max; i++)
{
if (i<len1 && ss[o+s1[i]]==0 && (--e1)<0) goto NoMatch;
if (i<len0 && ss[o+s0[i]]!=0 && (--e0)<0) goto NoMatch;
}
// Clear the image that has been found
for (i=0; i<len1; i++)
ss[o+s1[i]]=0;
}
allpos[ok*2]=k*sx+x; allpos[ok*2+1]=k*sy+y;
if (++ok>=allpos_max)
goto Return1;
NoMatch:
if (dir==1) goto GoBack1;
if (dir==2) goto GoBack2;
if (dir==3) goto GoBack3;
goto GoBack4;
//----------------------
Return1:
return ok;
}
*/
;==== Optional GUI interface ====
Gui(cmd, arg1:="")
{
local
static
global FindText
local lls, bch, cri
ListLines, % InStr("|KeyDown|LButtonDown|MouseMove|"
, "|" cmd "|") ? "Off" : A_ListLines
static init:=0
if (!init)
{
init:=1
Gui_:=ObjBindMethod(FindText,"Gui")
Gui_G:=ObjBindMethod(FindText,"Gui","G")
Gui_Run:=ObjBindMethod(FindText,"Gui","Run")
Gui_Off:=ObjBindMethod(FindText,"Gui","Off")
Gui_Show:=ObjBindMethod(FindText,"Gui","Show")
Gui_KeyDown:=ObjBindMethod(FindText,"Gui","KeyDown")
Gui_LButtonDown:=ObjBindMethod(FindText,"Gui","LButtonDown")
Gui_MouseMove:=ObjBindMethod(FindText,"Gui","MouseMove")
Gui_ScreenShot:=ObjBindMethod(FindText,"Gui","ScreenShot")
Gui_ShowPic:=ObjBindMethod(FindText,"Gui","ShowPic")
Gui_ToolTip:=ObjBindMethod(FindText,"Gui","ToolTip")
Gui_ToolTipOff:=ObjBindMethod(FindText,"Gui","ToolTipOff")
bch:=A_BatchLines, cri:=A_IsCritical
Critical
#NoEnv
%Gui_%("Load_Language_Text")
%Gui_%("MakeCaptureWindow")
%Gui_%("MakeMainWindow")
OnMessage(0x100, Gui_KeyDown)
OnMessage(0x201, Gui_LButtonDown)
OnMessage(0x200, Gui_MouseMove)
Menu, Tray, Add
Menu, Tray, Add, % Lang["1"], %Gui_Show%
if (!A_IsCompiled and A_LineFile=A_ScriptFullPath)
{
Menu, Tray, Default, % Lang["1"]
Menu, Tray, Click, 1
Menu, Tray, Icon, Shell32.dll, 23
}
Critical, %cri%
SetBatchLines, %bch%
}
Switch cmd
{
Case "Off":
return
Case "G":
GuiControl, +g, %id%, %Gui_Run%
return
Case "Run":
Critical
%Gui_%(A_GuiControl)
return
Case "Show":
Gui, FindText_Main: Default
Gui, Show, Center
GuiControl, Focus, scr
return
Case "MakeCaptureWindow":
ww:=35, hh:=12, WindowColor:="0xDDEEFF"
Gui, FindText_Capture: New
Gui, +AlwaysOnTop -DPIScale +HwndCapture_ID
Gui, Margin, 15, 15
Gui, Color, %WindowColor%
Gui, Font, s12, Verdana
Gui, -Theme
nW:=71, nH:=25, w:=12, C_:=[], Cid_:=[]
Loop, % nW*(nH+1)
{
i:=A_Index, j:=i=1 ? "" : Mod(i,nW)=1 ? "xm y+1":"x+1"
j.=i>nW*nH ? " cRed BackgroundFFFFAA" : ""
Gui, Add, Progress, w%w% h%w% %j% Hwndid
Control, ExStyle, -0x20000,, ahk_id %id%
C_[i]:=id, Cid_[id]:=i
}
Gui, +Theme
GuiControlGet, p, Pos, %id%
w:=pX+pW-15, h:=pY+pH-15
Gui, Add, Slider, xm w%w% vMySlider1 Hwndid Disabled
+Center Page20 Line10 NoTicks AltSubmit
%Gui_G%()
Gui, Add, Slider, ym h%h% vMySlider2 Hwndid Disabled
+Center Page20 Line10 NoTicks AltSubmit +Vertical
%Gui_G%()
GuiControlGet, p, Pos, %id%
k:=pX+pW, MySlider1:=MySlider2:=dx:=dy:=0
;--------------
Gui, Add, Button, xm Hwndid Hidden Section, % Lang["Auto"]
GuiControlGet, p, Pos, %id%
w:=Round(pW*0.75), i:=Round(w*3+15+pW*0.5-w*1.5)
Gui, Add, Button, xm+%i% yp w%w% hp -Wrap vRepU Hwndid, % Lang["RepU"]
%Gui_G%()
Gui, Add, Button, x+0 wp hp -Wrap vCutU Hwndid, % Lang["CutU"]
%Gui_G%()
Gui, Add, Button, x+0 wp hp -Wrap vCutU3 Hwndid, % Lang["CutU3"]
%Gui_G%()
Gui, Add, Button, xm wp hp -Wrap vRepL Hwndid, % Lang["RepL"]
%Gui_G%()
Gui, Add, Button, x+0 wp hp -Wrap vCutL Hwndid, % Lang["CutL"]
%Gui_G%()
Gui, Add, Button, x+0 wp hp -Wrap vCutL3 Hwndid, % Lang["CutL3"]
%Gui_G%()
Gui, Add, Button, x+15 w%pW% hp -Wrap vAuto Hwndid, % Lang["Auto"]
%Gui_G%()
Gui, Add, Button, x+15 w%w% hp -Wrap vRepR Hwndid, % Lang["RepR"]
%Gui_G%()
Gui, Add, Button, x+0 wp hp -Wrap vCutR Hwndid, % Lang["CutR"]
%Gui_G%()
Gui, Add, Button, x+0 wp hp -Wrap vCutR3 Hwndid, % Lang["CutR3"]
%Gui_G%()
Gui, Add, Button, xm+%i% wp hp -Wrap vRepD Hwndid, % Lang["RepD"]
%Gui_G%()
Gui, Add, Button, x+0 wp hp -Wrap vCutD Hwndid, % Lang["CutD"]
%Gui_G%()
Gui, Add, Button, x+0 wp hp -Wrap vCutD3 Hwndid, % Lang["CutD3"]
%Gui_G%()
;--------------
Gui, Add, Text, x+80 ys+3 Section, % Lang["SelGray"]
Gui, Add, Edit, x+3 yp-3 w60 vSelGray ReadOnly
Gui, Add, Text, x+15 ys, % Lang["SelColor"]
Gui, Add, Edit, x+3 yp-3 w120 vSelColor ReadOnly
Gui, Add, Text, x+15 ys, % Lang["SelR"]
Gui, Add, Edit, x+3 yp-3 w60 vSelR ReadOnly
Gui, Add, Text, x+5 ys, % Lang["SelG"]
Gui, Add, Edit, x+3 yp-3 w60 vSelG ReadOnly
Gui, Add, Text, x+5 ys, % Lang["SelB"]
Gui, Add, Edit, x+3 yp-3 w60 vSelB ReadOnly
;--------------
x:=w*6+pW+15*4, w:=k-x
Gui, Add, Tab3, x%x% y+15 w%w% -Wrap, % Lang["2"]
Gui, Tab, 1
Gui, Add, Text, x+15 y+15, % Lang["Threshold"]
Gui, Add, Edit, x+15 w100 vThreshold
Gui, Add, Button, x+15 yp-3 vGray2Two Hwndid, % Lang["Gray2Two"]
%Gui_G%()
Gui, Tab, 2
Gui, Add, Text, x+15 y+15, % Lang["GrayDiff"]
Gui, Add, Edit, x+15 w100 vGrayDiff, 50
Gui, Add, Button, x+15 yp-3 vGrayDiff2Two Hwndid, % Lang["GrayDiff2Two"]
%Gui_G%()
Gui, Tab, 3
Gui, Add, Text, x+15 y+15, % Lang["Similar1"] " 0"
Gui, Add, Slider, x+0 w120 vSimilar1 Hwndid
+Center Page1 NoTicks ToolTip, 100
%Gui_G%()
Gui, Add, Text, x+0, 100
Gui, Add, Button, x+15 yp-3 vColor2Two Hwndid, % Lang["Color2Two"]
%Gui_G%()
Gui, Tab, 4
Gui, Add, Text, x+15 y+15, % Lang["Similar2"] " 0"
Gui, Add, Slider, x+0 w120 vSimilar2 Hwndid
+Center Page1 NoTicks ToolTip, 100
%Gui_G%()
Gui, Add, Text, x+0, 100
Gui, Add, Button, x+15 yp-3 vColorPos2Two Hwndid, % Lang["ColorPos2Two"]
%Gui_G%()
Gui, Tab, 5
Gui, Add, Text, x+10 y+15, % Lang["DiffR"]
Gui, Add, Edit, x+5 w80 vDiffR Limit3
Gui, Add, UpDown, vdR Range0-255 Wrap
Gui, Add, Text, x+5, % Lang["DiffG"]
Gui, Add, Edit, x+5 w80 vDiffG Limit3
Gui, Add, UpDown, vdG Range0-255 Wrap
Gui, Add, Text, x+5, % Lang["DiffB"]
Gui, Add, Edit, x+5 w80 vDiffB Limit3
Gui, Add, UpDown, vdB Range0-255 Wrap
Gui, Add, Button, x+15 yp-3 vColorDiff2Two Hwndid, % Lang["ColorDiff2Two"]
%Gui_G%()
Gui, Tab, 6
Gui, Add, Text, x+10 y+15, % Lang["DiffRGB"]
Gui, Add, Edit, x+5 w80 vDiffRGB Limit3
Gui, Add, UpDown, vdRGB Range0-255 Wrap
Gui, Add, Checkbox, x+15 yp+5 vMultiColor Hwndid, % Lang["MultiColor"]
%Gui_G%()
Gui, Add, Button, x+15 yp-5 vUndo Hwndid, % Lang["Undo"]
%Gui_G%()
Gui, Tab
;--------------
Gui, Add, Button, xm vReset Hwndid, % Lang["Reset"]
%Gui_G%()
Gui, Add, Checkbox, x+15 yp+5 vModify Hwndid, % Lang["Modify"]
%Gui_G%()
Gui, Add, Text, x+30, % Lang["Comment"]
Gui, Add, Edit, x+5 yp-2 w150 vComment
Gui, Add, Button, x+30 yp-3 vSplitAdd Hwndid, % Lang["SplitAdd"]
%Gui_G%()
Gui, Add, Button, x+10 vAllAdd Hwndid, % Lang["AllAdd"]
%Gui_G%()
Gui, Add, Button, x+10 wp vButtonOK Hwndid, % Lang["ButtonOK"]
%Gui_G%()
Gui, Add, Button, x+10 wp vClose gCancel, % Lang["Close"]
Gui, Add, Button, xm vBind0 Hwndid, % Lang["Bind0"]
%Gui_G%()
Gui, Add, Button, x+15 vBind1 Hwndid, % Lang["Bind1"]
%Gui_G%()
Gui, Add, Button, x+15 vBind2 Hwndid, % Lang["Bind2"]
%Gui_G%()
Gui, Add, Button, x+15 vBind3 Hwndid, % Lang["Bind3"]
%Gui_G%()
Gui, Add, Button, x+15 vBind4 Hwndid, % Lang["Bind4"]
%Gui_G%()
Gui, Show, Hide, % Lang["3"]
return
Case "MakeMainWindow":
Gui, FindText_Main: New
Gui, +AlwaysOnTop -DPIScale
Gui, Margin, 15, 15
Gui, Color, %WindowColor%
Gui, Font, s12, Verdana
Gui, Add, Text, xm, % Lang["NowHotkey"]
Gui, Add, Edit, x+5 w200 vNowHotkey ReadOnly
Gui, Add, Hotkey, x+5 w200 vSetHotkey1
Gui, Add, DDL, x+5 w180 vSetHotkey2
, % "||F1|F2|F3|F4|F5|F6|F7|F8|F9|F10|F11|F12|MButton"
. "|ScrollLock|CapsLock|Ins|Esc|BS|Del|Tab|Home|End|PgUp|PgDn"
. "|NumpadDot|NumpadSub|NumpadAdd|NumpadDiv|NumpadMult"
Gui, Add, GroupBox, xm y+0 w280 h55 vMyGroup cBlack
Gui, Add, Text, xp+15 yp+20 Section, % Lang["Myww"] ": "
Gui, Add, Text, x+0 w60, %ww%
Gui, Add, UpDown, vMyww Range1-50, %ww%
Gui, Add, Text, x+15 ys, % Lang["Myhh"] ": "
Gui, Add, Text, x+0 w60, %hh%
Gui, Add, UpDown, vMyhh Hwndid Range1-50, %hh%
GuiControlGet, p, Pos, %id%
GuiControl, Move, MyGroup, % "w" (pX+pW) " h" (pH+30)
x:=pX+pW+15*2
Gui, Add, Button, x%x% ys-8 w150 vApply Hwndid, % Lang["Apply"]
%Gui_G%()
Gui, Add, Checkbox, x+30 ys Checked vAddFunc, % Lang["AddFunc"] " FindText()"
Gui, Add, Button, xm y+18 w144 vCutL2 Hwndid, % Lang["CutL2"]
%Gui_G%()
Gui, Add, Button, x+0 wp vCutR2 Hwndid, % Lang["CutR2"]
%Gui_G%()
Gui, Add, Button, x+0 wp vCutU2 Hwndid, % Lang["CutU2"]
%Gui_G%()
Gui, Add, Button, x+0 wp vCutD2 Hwndid, % Lang["CutD2"]
%Gui_G%()
Gui, Add, Button, x+0 wp vUpdate Hwndid, % Lang["Update"]
%Gui_G%()
Gui, Font, s6 bold, Verdana
Gui, Add, Edit, xm y+10 w720 r20 vMyPic -Wrap
Gui, Font, s12 norm, Verdana
Gui, Add, Button, xm w240 vCapture Hwndid, % Lang["Capture"]
%Gui_G%()
Gui, Add, Button, x+0 wp vTest Hwndid, % Lang["Test"]
%Gui_G%()
Gui, Add, Button, x+0 wp vCopy Hwndid, % Lang["Copy"]
%Gui_G%()
Gui, Add, Button, xm y+0 wp vCaptureS Hwndid, % Lang["CaptureS"]
%Gui_G%()
Gui, Add, Button, x+0 wp vGetRange Hwndid, % Lang["GetRange"]
%Gui_G%()
Gui, Add, Button, x+0 wp vTestClip Hwndid, % Lang["TestClip"]
%Gui_G%()
Gui, Font, s12 cBlue, Verdana
Gui, Add, Edit, xm w720 h350 vscr Hwndhscr -Wrap HScroll
Gui, Show, Hide, % Lang["4"]
return
Case "Capture","CaptureS":
Critical
Gui, FindText_Main: +Hwndid
if (show_gui:=(WinExist()=id))
{
Gui, FindText_Main: Default
Gui, +LastFound
WinMinimize
Gui, Hide
}
ShowScreenShot:=InStr(cmd,"CaptureS")
if (ShowScreenShot)
FindText.ShowScreenShot(1)
;----------------------
Gui, FindText_HotkeyIf: New, -Caption +ToolWindow +E0x80000
Gui, Show, NA x0 y0 w0 h0, FindText_HotkeyIf
Hotkey, IfWinExist, FindText_HotkeyIf
Hotkey, *RButton, %Gui_Off%, On UseErrorLevel
ListLines, % (lls:=A_ListLines)?"Off":"Off"
CoordMode, Mouse
KeyWait, RButton
KeyWait, Ctrl
w:=ww, h:=hh, oldx:=oldy:="", r:=StrSplit(Lang["5"],"|")
if (!show_gui)
w:=20, h:=8
Loop
{
Sleep, 50
MouseGetPos, x, y, Bind_ID
if (!show_gui)
{
w:=x<=1 ? w-1 : x>=A_ScreenWidth-2 ? w+1:w
h:=y<=1 ? h-1 : y>=A_ScreenHeight-2 ? h+1:h
w:=(w<1 ? 1:w), h:=(h<1 ? 1:h)
}
%Gui_%("Mini_Show")
if (oldx=x and oldy=y)
Continue
oldx:=x, oldy:=y
ToolTip, % r.1 " : " x "," y "`n" r.2
}
Until GetKeyState("RButton","P") or GetKeyState("Ctrl","P")
KeyWait, RButton
KeyWait, Ctrl
px:=x, py:=y, oldx:=oldy:=""
Loop
{
Sleep, 50
%Gui_%("Mini_Show")
MouseGetPos, x1, y1
if (oldx=x1 and oldy=y1)
Continue
oldx:=x1, oldy:=y1
ToolTip, % r.1 " : " x "," y "`n" r.2
}
Until GetKeyState("RButton","P") or GetKeyState("Ctrl","P")
KeyWait, RButton
KeyWait, Ctrl
ToolTip
%Gui_%("Mini_Hide")
ListLines, %lls%
Hotkey, *RButton, %Gui_Off%, Off UseErrorLevel
Hotkey, IfWinExist
Gui, FindText_HotkeyIf: Destroy
if (ShowScreenShot)
FindText.ShowScreenShot(0)
if (!show_gui)
return [px-w, py-h, px+w, py+h]
;-----------------------
%Gui_%("getcors", !ShowScreenShot)
%Gui_%("Reset")
Gui, FindText_Capture: Default
Loop, 71
GuiControl,, % C_[71*25+A_Index], 0
Loop, 6
GuiControl,, Edit%A_Index%
GuiControl,, Modify, % Modify:=0
GuiControl,, MultiColor, % MultiColor:=0
GuiControl,, GrayDiff, 50
GuiControl, Focus, Gray2Two
GuiControl, +Default, Gray2Two
Gui, Show, Center
Event:=Result:=""
DetectHiddenWindows, Off
Critical, Off
WinWaitClose, ahk_id %Capture_ID%
Critical
ToolTip
Gui, FindText_Main: Default
;--------------------------------
if (cors.bind!="")
{
WinGetTitle, tt, ahk_id %Bind_ID%
WinGetClass, tc, ahk_id %Bind_ID%
tt:=Trim(SubStr(tt,1,30) (tc ? " ahk_class " tc:""))
tt:=StrReplace(RegExReplace(tt,"[;``]","``$0"),"""","""""")
Result:="`nSetTitleMatchMode, 2`nid:=WinExist(""" tt """)"
. "`nFindText.BindWindow(id" (cors.bind=0 ? "":"," cors.bind)
. ") `; " Lang["6"] " FindText.BindWindow(0)`n`n" Result
}
if (Event="ButtonOK")
{
if (!A_IsCompiled)
{
FileRead, s, %A_LineFile%
s:=SubStr(s, s~="i)\n[;=]+ Copy The")
}
else s:=""
GuiControl,, scr, % Result "`n" s
if !InStr(Result,"##")
GuiControl,, MyPic, % Trim(FindText.ASCII(Result),"`n")
Result:=s:=""
}
else if (Event="SplitAdd") or (Event="AllAdd")
{
GuiControlGet, s,, scr
i:=j:=0, r:="<[^>\n]*>[^$\n]+\$[\w+/,.\-]+"
While j:=RegExMatch(s,r,"",j+1)
i:=InStr(s,"`n",0,j)
GuiControl,, scr, % SubStr(s,1,i) . Result . SubStr(s,i+1)
if !InStr(Result,"##")
GuiControl,, MyPic, % Trim(FindText.ASCII(Result),"`n")
Result:=s:=""
}
;----------------------
Gui, Show
GuiControl, Focus, scr
return
Case "Mini_Show":
Gui, FindText_Mini_4: +LastFoundExist
IfWinNotExist
{
Loop, 4
{
i:=A_Index
Gui, FindText_Mini_%i%: +AlwaysOnTop -Caption +ToolWindow -DPIScale +E0x08000000
Gui, FindText_Mini_%i%: Show, Hide, Mini
}
}
d:=2, w:=w<0 ? 0:w, h:=h<0 ? 0:h, c:=A_MSec<500 ? "Red":"Blue"
Loop, 4
{
i:=A_Index
x1:=Floor(i=3 ? x+w+1 : x-w-d)
y1:=Floor(i=4 ? y+h+1 : y-h-d)
w1:=Floor(i=1 or i=3 ? d : 2*(w+d)+1)
h1:=Floor(i=2 or i=4 ? d : 2*(h+d)+1)
Gui, FindText_Mini_%i%: Color, %c%
Gui, FindText_Mini_%i%: Show, NA x%x1% y%y1% w%w1% h%h1%
}
return
Case "Mini_Hide":
Gui, FindText_Mini_4: +Hwndid
Loop, 4
Gui, FindText_Mini_%A_Index%: Destroy
WinWaitClose, ahk_id %id%,, 3
return
Case "getcors":
FindText.xywh2xywh(px-ww,py-hh,2*ww+1,2*hh+1,x,y,w,h)
if (w<1 or h<1)
return
SetBatchLines, % (bch:=A_BatchLines)?"-1":"-1"
if (arg1) or (!FindText.GetBitsFromScreen(0,0,0,0,0).hBM)
FindText.ScreenShot()
cors:=[], gray:=[], k:=0
ListLines, % (lls:=A_ListLines)?"Off":"Off"
Loop, %nH%
{
j:=py-hh+A_Index-1, i:=px-ww
Loop, %nW%
cors[++k]:=c:=FindText.GetColor(i++,j,0)
, gray[k]:=(((c>>16)&0xFF)*38+((c>>8)&0xFF)*75+(c&0xFF)*15)>>7
}
ListLines, %lls%
cors.CutLeft:=Abs(px-ww-x)
cors.CutRight:=Abs(px+ww-(x+w-1))
cors.CutUp:=Abs(py-hh-y)
cors.CutDown:=Abs(py+hh-(y+h-1))
SetBatchLines, %bch%
return
Case "GetRange":
Critical
Gui, FindText_Main: +Hwndid
if (show_gui:=(WinExist()=id))
Gui, FindText_Main: Hide
;---------------------
Gui, FindText_GetRange: New
Gui, +LastFound +AlWaysOnTop +ToolWindow -Caption -DPIScale +E0x08000000
Gui, Color, White
WinSet, Transparent, 10
FindText.xywh2xywh(0,0,0,0,0,0,0,0,x,y,w,h)
Gui, Show, NA x%x% y%y% w%w% h%h%, GetRange
;---------------------
Gui, FindText_HotkeyIf: New, -Caption +ToolWindow +E0x80000
Gui, Show, NA x0 y0 w0 h0, FindText_HotkeyIf
Hotkey, IfWinExist, FindText_HotkeyIf
Hotkey, *LButton, %Gui_Off%, On UseErrorLevel
ListLines, % (lls:=A_ListLines)?"Off":"Off"
CoordMode, Mouse
KeyWait, LButton
KeyWait, Ctrl
oldx:=oldy:="", r:=Lang["7"]
Loop
{
Sleep, 50
MouseGetPos, x, y
if (oldx=x and oldy=y)
Continue
oldx:=x, oldy:=y
ToolTip, %r%
}
Until GetKeyState("LButton","P") or GetKeyState("Ctrl","P")
px:=x, py:=y, oldx:=oldy:=""
Loop
{
Sleep, 50
MouseGetPos, x, y
w:=Abs(px-x)//2, h:=Abs(py-y)//2, x:=(px+x)//2, y:=(py+y)//2
%Gui_%("Mini_Show")
if (oldx=x and oldy=y)
Continue
oldx:=x, oldy:=y
ToolTip, %r%
}
Until !(GetKeyState("LButton","P") or GetKeyState("Ctrl","P"))
ToolTip
%Gui_%("Mini_Hide")
ListLines, %lls%
Hotkey, *LButton, %Gui_Off%, Off UseErrorLevel
Hotkey, IfWinExist
Gui, FindText_HotkeyIf: Destroy
Gui, FindText_GetRange: Destroy
Clipboard:=p:=(x-w) ", " (y-h) ", " (x+w) ", " (y+h)
if (!show_gui)
return StrSplit(p, ",", " ")
;---------------------
Gui, FindText_Main: Default
GuiControlGet, s,, scr
if RegExMatch(s, "i)(=\s*FindText\()([^,]*,){4}", r)
{
s:=StrReplace(s, r, r1 . p ",", 0, 1)
GuiControl,, scr, %s%
}
Gui, Show
return
Case "Test","TestClip":
Gui, FindText_Main: Default
Gui, +LastFound
WinMinimize
Gui, Hide
DetectHiddenWindows, Off
WinWaitClose, % "ahk_id " WinExist()
Sleep, 100
;----------------------
if (cmd="Test")
GuiControlGet, s,, scr
else
s:=Clipboard
if (!A_IsCompiled) and InStr(s,"MCode(") and (cmd="Test")
{
s:="`n#NoEnv`nMenu, Tray, Click, 1`n" s "`nExitApp`n"
Thread:= new FindText.Thread(s)
DetectHiddenWindows, On
WinWait, % "ahk_class AutoHotkey ahk_pid " Thread.pid,, 3
if (!ErrorLevel)
WinWaitClose,,, 30
Thread:="" ; kill the Thread
}
else
{
Gui, +OwnDialogs
t:=A_TickCount, n:=150000
, RegExMatch(s,"<[^>\n]*>[^$\n]+\$[\w+/,.\-]+",v)
, ok:=FindText.FindText(-n, -n, n, n, 0, 0, v)
, X:=ok.1.x, Y:=ok.1.y, Comment:=ok.1.id
r:=StrSplit(Lang["8"],"|")
MsgBox, 4096, Tip, % r.1 ":`t" Round(ok.MaxIndex()) "`n`n"
. r.2 ":`t" (A_TickCount-t) " " r.3 "`n`n"
. r.4 ":`t" X ", " Y "`n`n"
. r.5 ":`t" (ok ? r.6 " ! " Comment : r.7 " !"), 3
for i,v in ok
if (i<=2)
FindText.MouseTip(ok[i].x, ok[i].y)
ok:=""
}
;----------------------
Gui, Show
GuiControl, Focus, scr
return
Case "Copy":
Gui, FindText_Main: Default
ControlGet, s, Selected,,, ahk_id %hscr%
if (s="")
{
GuiControlGet, s,, scr
GuiControlGet, r,, AddFunc
if (r != 1)
s:=RegExReplace(s,"\n\K[\s;=]+ Copy The[\s\S]*")
}
Clipboard:=RegExReplace(s,"\R","`r`n")
;----------------------
Gui, Hide
Sleep, 100
Gui, Show
GuiControl, Focus, scr
return
Case "Apply":
Gui, FindText_Main: Default
GuiControlGet, NowHotkey
GuiControlGet, SetHotkey1
GuiControlGet, SetHotkey2
if (NowHotkey!="")
Hotkey, *%NowHotkey%,, Off UseErrorLevel
k:=SetHotkey1!="" ? SetHotkey1 : SetHotkey2
if (k!="")
Hotkey, *%k%, %Gui_ScreenShot%, On UseErrorLevel
GuiControl,, NowHotkey, %k%
GuiControl,, SetHotkey1
GuiControl, Choose, SetHotkey2, 0
;------------------------
GuiControlGet, Myww
GuiControlGet, Myhh
if (Myww!=ww or Myhh!=hh)
{
nW:=71, dx:=dy:=0
Loop, % 71*25
k:=A_Index, c:=WindowColor, %Gui_%("SetColor")
ww:=Myww, hh:=Myhh, nW:=2*ww+1, nH:=2*hh+1
i:=nW>71, j:=nH>25
Gui, FindText_Capture: Default
GuiControl, Enable%i%, MySlider1
GuiControl, Enable%j%, MySlider2
GuiControl,, MySlider1, % MySlider1:=0
GuiControl,, MySlider2, % MySlider2:=0
}
return
Case "ScreenShot":
Critical
FindText.ScreenShot()
Gui, FindText_Tip: New
; WS_EX_NOACTIVATE:=0x08000000, WS_EX_TRANSPARENT:=0x20
Gui, +LastFound +AlwaysOnTop +ToolWindow -Caption -DPIScale +E0x08000020
Gui, Color, Yellow
Gui, Font, cRed s48 bold
Gui, Add, Text,, % Lang["9"]
WinSet, Transparent, 200
Gui, Show, NA y0, ScreenShot Tip
Sleep, 1000
Gui, Destroy
return
Case "Bind0","Bind1","Bind2","Bind3","Bind4":
Critical
FindText.BindWindow(Bind_ID, bind_mode:=SubStr(cmd,0))
Gui, FindText_HotkeyIf: New, -Caption +ToolWindow +E0x80000
Gui, Show, NA x0 y0 w0 h0, FindText_HotkeyIf
Hotkey, IfWinExist, FindText_HotkeyIf
Hotkey, *RButton, %Gui_Off%, On UseErrorLevel
ListLines, % (lls:=A_ListLines)?"Off":"Off"
CoordMode, Mouse
KeyWait, RButton
KeyWait, Ctrl
oldx:=oldy:=""
Loop
{
Sleep, 50
MouseGetPos, x, y
if (oldx=x and oldy=y)
Continue
oldx:=x, oldy:=y
;---------------
px:=x, py:=y, %Gui_%("getcors",1)
%Gui_%("Reset"), r:=StrSplit(Lang["10"],"|")
ToolTip, % r.1 " : " x "," y "`n" r.2
}
Until GetKeyState("RButton","P") or GetKeyState("Ctrl","P")
KeyWait, RButton
KeyWait, Ctrl
ToolTip
ListLines, %lls%
Hotkey, *RButton, %Gui_Off%, Off UseErrorLevel
Hotkey, IfWinExist
Gui, FindText_HotkeyIf: Destroy
FindText.BindWindow(0), cors.bind:=bind_mode
return
Case "MySlider1","MySlider2":
Thread, Priority, 10
Critical, Off
dx:=nW>71 ? Round((nW-71)*MySlider1/100) : 0
dy:=nH>25 ? Round((nH-25)*MySlider2/100) : 0
if (oldx=dx and oldy=dy)
return
oldx:=dx, oldy:=dy, k:=0
Loop, % nW*nH
c:=(!show[++k] ? WindowColor
: bg="" ? cors[k] : ascii[k]
? "Black":"White"), %Gui_%("SetColor")
if (cmd="MySlider2")
return
Loop, 71
GuiControl,, % C_[71*25+A_Index], 0
Loop, % nW
{
i:=A_Index-dx
if (i>=1 && i<=71 && show[nW*nH+A_Index])
GuiControl,, % C_[71*25+i], 100
}
return
Case "Reset":
show:=[], ascii:=[], bg:=""
CutLeft:=CutRight:=CutUp:=CutDown:=k:=0
Loop, % nW*nH
show[++k]:=1, c:=cors[k], %Gui_%("SetColor")
Loop, % cors.CutLeft
%Gui_%("CutL")
Loop, % cors.CutRight
%Gui_%("CutR")
Loop, % cors.CutUp
%Gui_%("CutU")
Loop, % cors.CutDown
%Gui_%("CutD")
return
Case "SetColor":
if (nW=71 && nH=25)
tk:=k
else
{
tx:=Mod(k-1,nW)-dx, ty:=(k-1)//nW-dy
if (tx<0 || tx>=71 || ty<0 || ty>=25)
return
tk:=ty*71+tx+1
}
c:=c="Black" ? 0x000000 : c="White" ? 0xFFFFFF
: ((c&0xFF)<<16)|(c&0xFF00)|((c&0xFF0000)>>16)
SendMessage, 0x2001, 0, c,, % "ahk_id " . C_[tk]
return
Case "RepColor":
show[k]:=1, c:=(bg="" ? cors[k] : ascii[k]
? "Black":"White"), %Gui_%("SetColor")
return
Case "CutColor":
show[k]:=0, c:=WindowColor, %Gui_%("SetColor")
return
Case "RepL":
if (CutLeft<=cors.CutLeft)
or (bg!="" and InStr(color,"**")
and CutLeft=cors.CutLeft+1)
return
k:=CutLeft-nW, CutLeft--
Loop, %nH%
k+=nW, (A_Index>CutUp and A_Index<nH+1-CutDown
? %Gui_%("RepColor") : "")
return
Case "CutL":
if (CutLeft+CutRight>=nW)
return
CutLeft++, k:=CutLeft-nW
Loop, %nH%
k+=nW, (A_Index>CutUp and A_Index<nH+1-CutDown
? %Gui_%("CutColor") : "")
return
Case "CutL3":
Loop, 3
%Gui_%("CutL")
return
Case "RepR":
if (CutRight<=cors.CutRight)
or (bg!="" and InStr(color,"**")
and CutRight=cors.CutRight+1)
return
k:=1-CutRight, CutRight--
Loop, %nH%
k+=nW, (A_Index>CutUp and A_Index<nH+1-CutDown
? %Gui_%("RepColor") : "")
return
Case "CutR":
if (CutLeft+CutRight>=nW)
return
CutRight++, k:=1-CutRight
Loop, %nH%
k+=nW, (A_Index>CutUp and A_Index<nH+1-CutDown
? %Gui_%("CutColor") : "")
return
Case "CutR3":
Loop, 3
%Gui_%("CutR")
return
Case "RepU":
if (CutUp<=cors.CutUp)
or (bg!="" and InStr(color,"**")
and CutUp=cors.CutUp+1)
return
k:=(CutUp-1)*nW, CutUp--
Loop, %nW%
k++, (A_Index>CutLeft and A_Index<nW+1-CutRight
? %Gui_%("RepColor") : "")
return
Case "CutU":
if (CutUp+CutDown>=nH)
return
CutUp++, k:=(CutUp-1)*nW
Loop, %nW%
k++, (A_Index>CutLeft and A_Index<nW+1-CutRight
? %Gui_%("CutColor") : "")
return
Case "CutU3":
Loop, 3
%Gui_%("CutU")
return
Case "RepD":
if (CutDown<=cors.CutDown)
or (bg!="" and InStr(color,"**")
and CutDown=cors.CutDown+1)
return
k:=(nH-CutDown)*nW, CutDown--
Loop, %nW%
k++, (A_Index>CutLeft and A_Index<nW+1-CutRight
? %Gui_%("RepColor") : "")
return
Case "CutD":
if (CutUp+CutDown>=nH)
return
CutDown++, k:=(nH-CutDown)*nW
Loop, %nW%
k++, (A_Index>CutLeft and A_Index<nW+1-CutRight
? %Gui_%("CutColor") : "")
return
Case "CutD3":
Loop, 3
%Gui_%("CutD")
return
Case "Gray2Two":
Gui, FindText_Capture: Default
GuiControl, Focus, Threshold
GuiControlGet, Threshold
if (Threshold="")
{
pp:=[]
Loop, 256
pp[A_Index-1]:=0
Loop, % nW*nH
if (show[A_Index])
pp[gray[A_Index]]++
IP:=IS:=0
Loop, 256
k:=A_Index-1, IP+=k*pp[k], IS+=pp[k]
Threshold:=Floor(IP/IS)
Loop, 20
{
LastThreshold:=Threshold
IP1:=IS1:=0
Loop, % LastThreshold+1
k:=A_Index-1, IP1+=k*pp[k], IS1+=pp[k]
IP2:=IP-IP1, IS2:=IS-IS1
if (IS1!=0 and IS2!=0)
Threshold:=Floor((IP1/IS1+IP2/IS2)/2)
if (Threshold=LastThreshold)
Break
}
GuiControl,, Threshold, %Threshold%
}
Threshold:=Round(Threshold)
color:="*" Threshold, k:=i:=0
Loop, % nW*nH
{
ascii[++k]:=v:=(gray[k]<=Threshold)
if (show[k])
i:=(v?i+1:i-1), c:=(v?"Black":"White"), %Gui_%("SetColor")
}
bg:=i>0 ? "1":"0"
return
Case "GrayDiff2Two":
Gui, FindText_Capture: Default
GuiControlGet, GrayDiff
if (GrayDiff="")
{
Gui, +OwnDialogs
MsgBox, 4096, Tip, % "`n" Lang["11"] " !`n", 1
return
}
if (CutLeft=cors.CutLeft)
%Gui_%("CutL")
if (CutRight=cors.CutRight)
%Gui_%("CutR")
if (CutUp=cors.CutUp)
%Gui_%("CutU")
if (CutDown=cors.CutDown)
%Gui_%("CutD")
GrayDiff:=Round(GrayDiff)
color:="**" GrayDiff, k:=i:=0
Loop, % nW*nH
{
j:=gray[++k]+GrayDiff
, ascii[k]:=v:=( gray[k-1]>j or gray[k+1]>j
or gray[k-nW]>j or gray[k+nW]>j
or gray[k-nW-1]>j or gray[k-nW+1]>j
or gray[k+nW-1]>j or gray[k+nW+1]>j )
if (show[k])
i:=(v?i+1:i-1), c:=(v?"Black":"White"), %Gui_%("SetColor")
}
bg:=i>0 ? "1":"0"
return
Case "Color2Two","ColorPos2Two":
Gui, FindText_Capture: Default
GuiControlGet, c,, SelColor
if (c="")
{
Gui, +OwnDialogs
MsgBox, 4096, Tip, % "`n" Lang["12"] " !`n", 1
return
}
UsePos:=(cmd="ColorPos2Two") ? 1:0
GuiControlGet, n,, Similar1
n:=Round(n/100,2), color:=c "@" n
, n:=Floor(512*9*255*255*(1-n)*(1-n)), k:=i:=0
, rr:=(c>>16)&0xFF, gg:=(c>>8)&0xFF, bb:=c&0xFF
Loop, % nW*nH
{
c:=cors[++k], r:=((c>>16)&0xFF)-rr
, g:=((c>>8)&0xFF)-gg, b:=(c&0xFF)-bb, j:=r+rr+rr
, ascii[k]:=v:=((1024+j)*r*r+2048*g*g+(1534-j)*b*b<=n)
if (show[k])
i:=(v?i+1:i-1), c:=(v?"Black":"White"), %Gui_%("SetColor")
}
bg:=i>0 ? "1":"0"
return
Case "ColorDiff2Two":
Gui, FindText_Capture: Default
GuiControlGet, c,, SelColor
if (c="")
{
Gui, +OwnDialogs
MsgBox, 4096, Tip, % "`n" Lang["12"] " !`n", 1
return
}
GuiControlGet, dR
GuiControlGet, dG
GuiControlGet, dB
rr:=(c>>16)&0xFF, gg:=(c>>8)&0xFF, bb:=c&0xFF
, n:=Format("{:06X}",(dR<<16)|(dG<<8)|dB)
, color:=StrReplace(c "-" n,"0x"), k:=i:=0
Loop, % nW*nH
{
c:=cors[++k], r:=(c>>16)&0xFF, g:=(c>>8)&0xFF
, b:=c&0xFF, ascii[k]:=v:=(Abs(r-rr)<=dR
and Abs(g-gg)<=dG and Abs(b-bb)<=dB)
if (show[k])
i:=(v?i+1:i-1), c:=(v?"Black":"White"), %Gui_%("SetColor")
}
bg:=i>0 ? "1":"0"
return
Case "Modify":
GuiControlGet, Modify
return
Case "MultiColor":
GuiControlGet, MultiColor
Result:=""
ToolTip
return
Case "Undo":
Result:=RegExReplace(Result,",[^/]+/[^/]+/[^/]+$")
ToolTip, % Trim(Result,"/,")
return
Case "Similar1":
GuiControl, FindText_Capture:, Similar2, %Similar1%
return
Case "Similar2":
GuiControl, FindText_Capture:, Similar1, %Similar2%
return
Case "GetTxt":
txt:=""
if (bg="")
return
ListLines, % (lls:=A_ListLines)?"Off":"Off"
k:=0
Loop, %nH%
{
v:=""
Loop, %nW%
v.=!show[++k] ? "" : ascii[k] ? "1":"0"
txt.=v="" ? "" : v "`n"
}
ListLines, %lls%
return
Case "Auto":
%Gui_%("GetTxt")
if (txt="")
{
Gui, FindText_Capture: +OwnDialogs
MsgBox, 4096, Tip, % "`n" Lang["13"] " !`n", 1
return
}
While InStr(txt,bg)
{
if (txt~="^" bg "+\n")
txt:=RegExReplace(txt,"^" bg "+\n"), %Gui_%("CutU")
else if !(txt~="m`n)[^\n" bg "]$")
txt:=RegExReplace(txt,"m`n)" bg "$"), %Gui_%("CutR")
else if (txt~="\n" bg "+\n$")
txt:=RegExReplace(txt,"\n\K" bg "+\n$"), %Gui_%("CutD")
else if !(txt~="m`n)^[^\n" bg "]")
txt:=RegExReplace(txt,"m`n)^" bg), %Gui_%("CutL")
else Break
}
txt:=""
return
Case "ButtonOK","SplitAdd","AllAdd":
Gui, FindText_Capture: Default
Gui, +OwnDialogs
%Gui_%("GetTxt")
if (txt="") and (!MultiColor)
{
MsgBox, 4096, Tip, % "`n" Lang["13"] " !`n", 1
return
}
if InStr(color,"@") and (UsePos) and (!MultiColor)
{
r:=StrSplit(color,"@")
k:=i:=j:=0
Loop, % nW*nH
{
if (!show[++k])
Continue
i++
if (k=cors.SelPos)
{
j:=i
Break
}
}
if (j=0)
{
MsgBox, 4096, Tip, % "`n" Lang["12"] " !`n", 1
return
}
color:="#" (j-1) "@" r.2
}
GuiControlGet, Comment
if (cmd="SplitAdd") and (!MultiColor)
{
if InStr(color,"#")
{
MsgBox, 4096, Tip, % Lang["14"], 3
return
}
bg:=StrLen(StrReplace(txt,"0"))
> StrLen(StrReplace(txt,"1")) ? "1":"0"
s:="", i:=0, k:=nW*nH+1+CutLeft
Loop, % w:=nW-CutLeft-CutRight
{
i++
if (!show[k++] and A_Index<w)
Continue
i:=Format("{:d}",i)
v:=RegExReplace(txt,"m`n)^(.{" i "}).*","$1")
txt:=RegExReplace(txt,"m`n)^.{" i "}"), i:=0
While InStr(v,bg)
{
if (v~="^" bg "+\n")
v:=RegExReplace(v,"^" bg "+\n")
else if !(v~="m`n)[^\n" bg "]$")
v:=RegExReplace(v,"m`n)" bg "$")
else if (v~="\n" bg "+\n$")
v:=RegExReplace(v,"\n\K" bg "+\n$")
else if !(v~="m`n)^[^\n" bg "]")
v:=RegExReplace(v,"m`n)^" bg)
else Break
}
if (v!="")
{
v:=Format("{:d}",InStr(v,"`n")-1) "." FindText.bit2base64(v)
s.="`nText.=""|<" SubStr(Comment,1,1) ">" color "$" v """`n"
Comment:=SubStr(Comment, 2)
}
}
Event:=cmd, Result:=s
Gui, Hide
return
}
if (!MultiColor)
txt:=Format("{:d}",InStr(txt,"`n")-1) "." FindText.bit2base64(txt)
else
{
GuiControlGet, dRGB
r:=StrSplit(Trim(StrReplace(Result,",","/"),"/"),"/")
, x:=r.1, y:=r.2, s:="", i:=1
Loop, % r.MaxIndex()//3
s.="," (r[i++]-x) "/" (r[i++]-y) "/" r[i++]
txt:=SubStr(s,2), color:="##" dRGB
}
s:="`nText.=""|<" Comment ">" color "$" txt """`n"
if (cmd="AllAdd")
{
Event:=cmd, Result:=s
Gui, Hide
return
}
x:=px-ww+CutLeft+(nW-CutLeft-CutRight)//2
y:=py-hh+CutUp+(nH-CutUp-CutDown)//2
s:=StrReplace(s, "Text.=", "Text:="), r:=StrSplit(Lang["8"],"|")
s:="`; #Include <FindText>`n"
. "`n t1:=A_TickCount, X:=Y:=""""`n" s
. "`n if (ok:=FindText(" x "-150000, " y "-150000, " x "+150000, " y "+150000, 0, 0, Text))"
. "`n {"
. "`n CoordMode, Mouse"
. "`n X:=ok.1.x, Y:=ok.1.y, Comment:=ok.1.id"
. "`n `; Click, `%X`%, `%Y`%"
. "`n }`n"
. "`n MsgBox, 4096, Tip, `% """ r.1 ":``t"" Round(ok.MaxIndex())"
. "`n . ""``n``n" r.2 ":``t"" (A_TickCount-t1) "" " r.3 """"
. "`n . ""``n``n" r.4 ":``t"" X "", "" Y"
. "`n . ""``n``n" r.5 ":``t"" (ok ? """ r.6 " !"" : """ r.7 " !"")`n"
. "`n for i,v in ok"
. "`n if (i<=2)"
. "`n FindText.MouseTip(ok[i].x, ok[i].y)`n"
Event:=cmd, Result:=s
Gui, Hide
return
Case "KeyDown":
Critical
if (A_Gui="FindText_Main" && A_GuiControl="scr")
SetTimer, %Gui_ShowPic%, -150
return
Case "ShowPic":
ControlGet, i, CurrentLine,,, ahk_id %hscr%
ControlGet, s, Line, %i%,, ahk_id %hscr%
GuiControl, FindText_Main:, MyPic, % Trim(FindText.ASCII(s),"`n")
return
Case "LButtonDown":
Critical
if (A_Gui!="FindText_Capture")
return %Gui_%("KeyDown")
MouseGetPos,,,, k2, 2
if (k1:=Round(Cid_[k2]))<1
return
Gui, FindText_Capture: Default
if (k1>71*25)
{
GuiControlGet, k3,, %k2%
GuiControl,, %k2%, % k3 ? 0:100
show[nW*nH+(k1-71*25)+dx]:=(!k3)
return
}
k2:=Mod(k1-1,71)+dx, k3:=(k1-1)//71+dy
if (k2>=nW || k3>=nH)
return
k1:=k, k:=k3*nW+k2+1, k2:=c
if (MultiColor and show[k])
{
c:="," Mod(k-1,nW) "/" k3 "/"
. Format("{:06X}",cors[k]&0xFFFFFF)
, Result.=InStr(Result,c) ? "":c
ToolTip, % Trim(Result,"/,")
}
else if (Modify and bg!="" and show[k])
{
c:=((ascii[k]:=!ascii[k]) ? "Black":"White")
, %Gui_%("SetColor")
}
else
{
c:=cors[k], cors.SelPos:=k
GuiControl,, SelGray, % gray[k]
GuiControl,, SelColor, % Format("0x{:06X}",c&0xFFFFFF)
GuiControl,, SelR, % (c>>16)&0xFF
GuiControl,, SelG, % (c>>8)&0xFF
GuiControl,, SelB, % c&0xFF
}
k:=k1, c:=k2
return
Case "MouseMove":
static PrevControl:=""
if (PrevControl!=A_GuiControl)
{
PrevControl:=A_GuiControl
SetTimer, %Gui_ToolTip%, % PrevControl ? -500 : "Off"
SetTimer, %Gui_ToolTipOff%, % PrevControl ? -5500 : "Off"
ToolTip
}
return
Case "ToolTip":
MouseGetPos,,, _TT
IfWinExist, ahk_id %_TT% ahk_class AutoHotkeyGUI
ToolTip, % Tip_Text[PrevControl ""]
return
Case "ToolTipOff":
ToolTip
return
Case "CutL2","CutR2","CutU2","CutD2":
Gui, FindText_Main: Default
GuiControlGet, s,, MyPic
s:=Trim(s,"`n") . "`n", v:=SubStr(cmd,4,1)
if (v="U")
s:=RegExReplace(s,"^[^\n]+\n")
else if (v="D")
s:=RegExReplace(s,"[^\n]+\n$")
else if (v="L")
s:=RegExReplace(s,"m`n)^[^\n]")
else if (v="R")
s:=RegExReplace(s,"m`n)[^\n]$")
GuiControl,, MyPic, % Trim(s,"`n")
return
Case "Update":
Gui, FindText_Main: Default
GuiControl, Focus, scr
ControlGet, i, CurrentLine,,, ahk_id %hscr%
ControlGet, s, Line, %i%,, ahk_id %hscr%
if !RegExMatch(s,"(<[^>]*>[^$]+\$)\d+\.[\w+/]+",r)
return
GuiControlGet, v,, MyPic
v:=Trim(v,"`n") . "`n", w:=Format("{:d}",InStr(v,"`n")-1)
v:=StrReplace(StrReplace(v,"0","1"),"_","0")
s:=StrReplace(s,r,r1 . w "." FindText.bit2base64(v))
v:="{End}{Shift Down}{Home}{Shift Up}{Del}"
ControlSend,, %v%, ahk_id %hscr%
Control, EditPaste, %s%,, ahk_id %hscr%
ControlSend,, {Home}, ahk_id %hscr%
return
Case "Load_Language_Text":
s=
(
Myww = Width = Adjust the width of the capture range
Myhh = Height = Adjust the height of the capture range
AddFunc = Add = Additional FindText() in Copy
NowHotkey = Hotkey = Current screenshot hotkey
SetHotkey1 = = First sequence Screenshot hotkey
SetHotkey2 = = Second sequence Screenshot hotkey
Apply = Apply = Apply new screenshot hotkey and adjusted capture range values
CutU2 = CutU = Cut the Upper Edge of the text in the edit box below
CutL2 = CutL = Cut the Left Edge of the text in the edit box below
CutR2 = CutR = Cut the Right Edge of the text in the edit box below
CutD2 = CutD = Cut the Lower Edge of the text in the edit box below
Update = Update = Update the text in the edit box below to the line of code
GetRange = GetRange = Get screen range to clipboard and replace the range in the code
TestClip = TestClipboard = Test the Text data in the clipboard for searching images
Capture = Capture = Initiate Image Capture Sequence
CaptureS = CaptureS = Restore the last screenshot and then start capturing
Test = Test = Test Results of Code
Copy = Copy = Copy Code to Clipboard
Reset = Reset = Reset to Original Captured Image
SplitAdd = SplitAdd = Using Markup Segmentation to Generate Text Library
AllAdd = AllAdd = Append Another FindText Search Text into Previously Generated Code
ButtonOK = OK = Create New FindText Code for Testing
Close = Close = Close the Window Don't Do Anything
Gray2Two = Gray2Two = Converts Image Pixels from Gray Threshold to Black or White
GrayDiff2Two = GrayDiff2Two = Converts Image Pixels from Gray Difference to Black or White
Color2Two = Color2Two = Converts Image Pixels from Color Similar to Black or White
ColorPos2Two = ColorPos2Two = Converts Image Pixels from Color Position to Black or White
ColorDiff2Two = ColorDiff2Two = Converts Image Pixels from Color Difference to Black or White
SelGray = Gray = Gray value of the selected color
SelColor = Color = The selected color
SelR = R = Red component of the selected color
SelG = G = Green component of the selected color
SelB = B = Blue component of the selected color
RepU = -U = Undo Cut the Upper Edge by 1
CutU = U = Cut the Upper Edge by 1
CutU3 = U3 = Cut the Upper Edge by 3
RepL = -L = Undo Cut the Left Edge by 1
CutL = L = Cut the Left Edge by 1
CutL3 = L3 = Cut the Left Edge by 3
Auto = Auto = Automatic Cut Edge after image has been converted to black and white
RepR = -R = Undo Cut the Right Edge by 1
CutR = R = Cut the Right Edge by 1
CutR3 = R3 = Cut the Right Edge by 3
RepD = -D = Undo Cut the Lower Edge by 1
CutD = D = Cut the Lower Edge by 1
CutD3 = D3 = Cut the Lower Edge by 3
Modify = Modify = Allows Modify the Black and White Image
MultiColor = FindMultiColor = Click multiple colors with the mouse, then Click OK button
Undo = Undo = Undo the last selected color
Comment = Comment = Optional Comment used to Label Code ( Within <> )
Threshold = Gray Threshold = Gray Threshold which Determines Black or White Pixel Conversion (0-255)
GrayDiff = Gray Difference = Gray Difference which Determines Black or White Pixel Conversion (0-255)
Similar1 = Similarity = Adjust color similarity as Equivalent to The Selected Color
Similar2 = Similarity = Adjust color similarity as Equivalent to The Selected Color
DiffR = R = Red Difference which Determines Black or White Pixel Conversion (0-255)
DiffG = G = Green Difference which Determines Black or White Pixel Conversion (0-255)
DiffB = B = Blue Difference which Determines Black or White Pixel Conversion (0-255)
DiffRGB = R/G/B = Determine the allowed R/G/B Error (0-255) when Find MultiColor
Bind0 = BindWindow1 = Bind the window and Use GetDCEx() to get the image of background window
Bind1 = BindWindow1+ = Bind the window Use GetDCEx() and Modify the window to support transparency
Bind2 = BindWindow2 = Bind the window and Use PrintWindow() to get the image of background window
Bind3 = BindWindow2+ = Bind the window Use PrintWindow() and Modify the window to support transparency
Bind4 = BindWindow3 = Bind the window and Use PrintWindow(,,3) to get the image of background window
1 = FindText
2 = Gray|GrayDiff|Color|ColorPos|ColorDiff|MultiColor
3 = Capture Image To Text
4 = Capture Image To Text And Find Text Tool
5 = Position|First click RButton\nMove the mouse away\nSecond click RButton
6 = Unbind Window using
7 = Please drag a range with the LButton\nCoordinates are copied to clipboard
8 = Found|Time|ms|Pos|Result|Success|Failed
9 = Success
10 = The Capture Position|Perspective binding window\nRight click to finish capture
11 = Please Set Gray Difference First
12 = Please select the core color first
13 = Please convert the image to black or white first
14 = Can't be used in ColorPos mode, because it can cause position errors
)
Lang:=[], Tip_Text:=[]
Loop, Parse, s, `n, `r
if InStr(v:=A_LoopField, "=")
r:=StrSplit(StrReplace(v,"\n","`n"), "=", "`t ")
, Lang[r.1 ""]:=r.2, Tip_Text[r.1 ""]:=r.3
return
}
}
} ;// Class End
;================= The End =================
;