Here is a
TUTORIAL on different ways to use amazing MOUSECLICK
methods.
Basically if your FindText() image search finds multiples of the same image, then this allows you to choose which one.
These I have figured out over time due to lack of tutorials regarding which instances to click on after a FINDTEXT search, using its inbuilt Object/arrays.
Also below I show you how to change the
' Search Direction'
Version : 8.7 - Updated Date : 2022-01-24
4 different Click/Move methods
Method1:: MouseClick, Left, ok[1].x, ok[1].y, 1, 1
If you want to click on instance Number 4 of images found, then replace [1] with [4] e.g. MouseClick, Left, ok[4].x, ok[4].y, 1, 1
If you want to click/move on Image 2's X coordinate but Image 1's Y coordinate, then just do as follows
MouseMove, ok[2].x, ok[1].y, 3 AMAZING hey!!
Or combine multiple clicks/moves
Code: Select all
#Include <FindText> ; does not need to be added if your FindText.ahk script is in your \AutoHotkey\Lib' folder
x::
Text:="|<>D9D4D4-000000$6.SzzzzSU"
if (ok:=FindText(X, Y, 0, 0, 0, 0, 0, 0, Text,,,,,,1)) ; search range of ( 0,0,0,0 ) represents search entire Monitor Size
{
MouseClick, Left, ok[1].x, ok[1].y, 1, 1
MouseClick, Left, ok[3].x, ok[3].y, 1, 1
MouseMove, ok[5].x, ok[5].y, 1
}
return
--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
Method2:: Click(1) ; Can't control mouse speed, stays on whatever the function is set to
Replace (1) with (2) or (3) etc etc to click on different instances found.
This is just a quick way of coding a mouseclick function. It struggles when I use a loop scripts. but it can be super handy without loops.
Code: Select all
#Include <FindText>
x::
Text:="|<>D9D4D4-000000$6.SzzzzSU"
if (ok:=FindText(X, Y, 0, 0, 0, 0, 0, 0, Text,,,,,,1))
{
Click(1) ; you can combine them on one line if you wish Click(1), Click(3), Click(4)
Click(3)
Click(4)
}
return
----------------------------------------------
- For Method2:: Click(1) to actually work, please paste the below function into your #include <Findtext> script function.
I just paste it after the 1st FINDTEXT function ==> FindText(ByRef x:="FindTextClass", ByRef y:="", args*)
Code: Select all
Click(i) {
global ok
{
MouseClick,, ok[i].1+ok[i].3//2, ok[i].2+ok[i].4//2, 1, 1
Sleep, 111
}
}
--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
Method3:: FindText().Click(X, Y, "L")
This is an inbuilt 'click function' from the version that was updated in September 2021,
This script can be an all in one solution with my fix. now you can Change Click Up, Left, Right, Speed and instance
I have changed this function to add 'speed' on the end which is NEEDED!
So in the #include <FindText> script find the Click() function
Click(x:="", y:="", other:="") and swap it out with my small change.
Code: Select all
; ; Find this Fucniton
Click(x:="", y:="", other:="")
{
local
bak:=A_CoordModeMouse
CoordMode, Mouse, Screen
MouseMove, x, y, 0
Click, %x%, %y%, %other%
CoordMode, Mouse, %bak%
}
Now swap to with this one which adds a speed parameter.
Code: Select all
Click(x:="", y:="", other:="", speed:="")
{
local
bak:=A_CoordModeMouse
CoordMode, Mouse, Screen
MouseMove, x, y, %speed%
Click, %x%, %y%, %other%
CoordMode, Mouse, %bak%
}
Now that we have done that, this script can be an all in one solution.
So to choose which instance to click on just change your code to
FindText().Click(ok[1].x, ok[1].y, "U" , 1)
notice how there is now an added speed parameter on the end.
So Now you can Replace "L" with "U" for mouse move or "R" for right-click
--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
Method4:: FindText_Control_Click(ok, ok[1].x, ok[1].y, ahkEXE:="ahk_exe chrome.exe")
This is a control-click so the mouse doesn't move, so it instantly 'Clicks' on what you want. Change ok[1].x, ok[1].y to the image number you want to click on e.g.
ok[4].x, ok[4].y
- For Method4:: FindText_Control_Click(ok, ok[1].x, ok[1].y, ahkEXE:="ahk_exe chrome.exe") to actually work, Just add the below Function into your #include <Findtext> script function (see code below)
It was written by Joe Glines, I have modified it for the Current version.
Code: Select all
FindText_Control_Click(Obj,X,Y,ahkEXE=""){
;~ SetControlDelay -1 ( I turned off SetControlDelay here cause it was causing issues if I had it on my actual script, so I just set it to SetControlDelay -1 in my actual script
ControlClick,x%x% y%y%,ahk_exe %ahkEXE%,,,,NA
}
--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
Here is how you change the search Direction.
Text:="|<GREEN>0x0EC218@1.00$6.SzzzzSU"
if (ok:=FindText(X, Y, 0, 0, 1920, 1080, 0, 0, Text,,,,,,1))
After the
6 commas,,,,,, that is after the variable
"Text", change the "1" to change SEARCH Direction. e.g.
if (ok:=FindText(X, Y, 0, 0, 1920, 1080, 0, 0, Text,,,,,,6))
Also note, if your search range is
4 (0's) this actually represents search entire monitor screen.
if (ok:=FindText(X, Y, 0, 0, 0, 0, 0, 0, Text,,,,,,1))
But if you choose search from the centre outwards which is Number '9', then you can't have 4 '0's' , you must have a proper search range e.g.
if (ok:=FindText(X, Y, 0, 0, 1920, 1080, 0, 0, Text,,,,,,9))
@feiyue maybe add this Direction description to the top of this forum?
1 = Starts Top Left & Scans Right. then it scans again from 1 Pixel down from the Top Left and it scans Right again etc. etc.
2 = TR - Scan L
3 = BL Scan R
4 = BR scan L
5 = TL Scan D
6 = BL - Scan U
7 = TR Scan D
8 = BR scan U
9 = Starts at the Centre and scans outward in a circle