I am really impressed with FindText and prefer it over ImageSearch because of it's flexibility and I no longer have to include image files with my scripts. If you don't know about this function, read the link above or the rest of this won't make sense to you.feiyue wrote: ↑14 May 2016, 12:10FindText is a function similar to the AHK built-in command "ImageSearch",
but it can convert images into strings, written into the script without
saving as an external image, so it is easier to use than "ImageSearch".
https://www.autohotkey.com/boards/viewtopic.php?t=17834
tl;dr;
I have 3 monitors an have noticed that FindText was taking a few seconds to search my screen for images. In most cases I only need to search the active window so I created a wrapper function to do this for me. It will perform much faster now that it's range has been limited.
After adding my functions to your script, you should be able to immediately replace your calls to FindText with my new functions, FindTextAW (AW = Active Window) and FindTextAWClick.
Code: Select all
FindTextAW(text,err1:=0,err0:=0)
; FindText only within the active window. Much faster if you have a large
; desktop or are searching for multiple images.
; Input parameters x,y,w,h are not needed in this version and err1 and err0
; are optional parameters in case they are needed.
; This outputs the same array of x,y,w,h,Comment that the main function returns.
; Ben Sacherich - 7/17/2019
{
t1:=A_TickCount
WinGetPos, X, Y, W, H, A ; "A" to get the active window's position.
;SoundBeep 423, 100 ; Uncomment for debugging.
; Get the coordinates for the center of the window and pass that to the regular FindText function.
; This is needed for FindText versions prior to 6.0
;W:=W//2
;X+=W
;H:=H//2
;Y+=H
;MsgBox, Searching at %X%`, %Y%, %W%`, %H%
;if (ok:=FindText(X, Y, W, H, 0, 0, Text,1,0)) ; Take new Screenshot, Find First
if (ok:=FindText(X, Y, W, H, 0, 0, Text,1,1)) ; Take new Screenshot, Find All
{
CoordMode, Mouse
X:=ok.1.1, Y:=ok.1.2, W:=ok.1.3, H:=ok.1.4, Comment:=ok.1.5, X+=W//2, Y+=H//2
}
t1:=A_TickCount-t1
; Show a MouseTip on the first two matches. Uncomment for debugging.
;for i,v in ok
; if i<=2
; {
; MouseTip(v.1+v.3//2, v.2+v.4//2)
; Comment.=v.5 ", "
; }
;if ok ; Uncomment for debugging.
; MsgBox, 4096, % "FindTextAW", % "Time:`t" (t1) " ms`n`n"
; . "Pos:`t" X ", " Y "`n`n"
; . "Found:`t" ok.MaxIndex() "`n`n"
; . "Result:`t" (ok ? "Success!`n`n" Comment : "Failed!"),5
return, ok.MaxIndex() ? ok:0
}
Code: Select all
FindTextAWClick(text,err1:=0,err0:=0)
; FindText in the active window and click on it.
; This relies on FindTextAW().
; Ben Sacherich - 7/17/2019 - This saves me writing code that I was repeating a lot.
{
if (ok:=FindTextAW(Text))
{
CoordMode, Mouse
X:=ok.1.1, Y:=ok.1.2, W:=ok.1.3, H:=ok.1.4, Comment:=ok.1.5, X+=W//2, Y+=H//2
Click, %X%, %Y%
;MouseMove, X, Y ; Uncomment if you want the mouse to move to the click site.
SoundBeep 2000, 150 ; Let the user know something happened.
return, 1
}
}
Code: Select all
^r:: ; CTRL+r
; If the Microsoft Access Query Designer is open and in Design mode...(rest of algorithm removed)
; Looking for the Design Triangle in the bottom right corner of the window. It is hard to find this and not get a false positive.
Text:="|<Access Design Mode>[email protected]$55.zzzzzzzzzU0003zzzzk0001zzzzs0000zzzzw0000TzjzS0000DznzL00007zuz7cV003zxj7m6001zy/7u4U00zzT7wWE00TzjLy0U00DzkbzF2007zzzzU0003zy00k2001zzPPM0000zzjzg0000Tzk060000Dzzzz00007zzzzk"
if (ok:=FindTextAW(Text))
{
SoundBeep, 1000, 150
; Access Design Mode detected
CoordMode, Mouse
X:=ok.1.1, Y:=ok.1.2, W:=ok.1.3, H:=ok.1.4, Comment:=ok.1.5, X+=W//2, Y+=H//2
MsgBox, 64, Design Mode detected: %X%`, %Y%`, %Comment%, 4
; Do more stuff after we know Design Mode is active. No need to click on the icon.
}
+#q:: ; WIN+SHIFT+Q
IfWinExist ahk_class LyncConversationWindowClass ; Lync 2016 ; meeting window being shared. It may say "(5 Participants)" in the title.
{
IfWinNotActive ahk_class LyncConversationWindowClass
{
SoundBeep 423, 150
WinActivate ; Activates the window found by #IfWin.
; If the "Hide Stage" button is present, click it. It may be left over from a previous meeting.
Text:="|<Hide Stage>*156$58.zzzzzzzzzyyrvzsTzzzvvzjzjjzzzjjyzyyzzzyyr3XtkVkss3NBbnjqHNjhikTqsPg6yqvTz/hirvvPAzQiqnDjhUsS68MC7zzzzzzzyzzzzzzzzznzzzzzzzzsTzzzzzzzzzzs"
FindTextAWClick(Text)
Return
}
}