How can I get the coordinates, width, and height of the area that I want to use for Imagesearch? Topic is solved
How can I get the coordinates, width, and height of the area that I want to use for Imagesearch?
Also do you recommend searching within a bigger space, let's say 10% bigger?
Re: How can I get the coordinates, width, and height of the area that I want to use for Imagesearch?
Well, one important thing to realize is that ImageSearch’s parameters do not include width and height. The parameters include the x,y coordinates of the upper-left corner of the search rectangle and the x,y coordinates of the lower-right corner.
Other than that, I’m not sure what kind of answer you would expect someone else to provide for this. You are the one who presumably knows where the image could potentially appear, and that defines the coordinates. I believe you already know how to use the Window Spy tool to get the locations of certain coordinates.
No, there is no reason to do that. Just make sure the image you are searching for would fall completely within the defined search rectangle.
Re: How can I get the coordinates, width, and height of the area that I want to use for Imagesearch?
Did I make this correctly:
Can you tell me that difference between the error levels, 0 - 2?
Code: Select all
^+u::
Run, C:\Program Files\Waterfox\waterfox.exe postimages.org
WinWaitActive, Postimages ahk_exe waterfox.exe
ImageSearch, OutputVarx, OutputVarY, 759, 618, 1155, 674, Choose ImageSearch.PNG
if (ErrorLevel = 0)
Click 929 644
return
Can you tell me that difference between the error levels, 0 - 2?
Re: How can I get the coordinates, width, and height of the area that I want to use for Imagesearch?
It generally looks correct, but I don't know if your coordinates are correct, you're basing them off the right reference point (i.e., window vs. screen coordinates per CoordMode), the image file is in the correct place, the image file is a good representation of the image to be found, etc.
I don't know how to make it any more clear than what is already in the documentation:
What is it about that description that you don't understand?ErrorLevel is set to 0 if the image was found in the specified region, 1 if it was not found, or 2 if there was a problem that prevented the command from conducting the search (such as failure to open the image file or a badly formatted option).
Re: How can I get the coordinates, width, and height of the area that I want to use for Imagesearch?
Hallo,
to get the screen coordinates of the area:
to get the screen coordinates of the area:
Code: Select all
; First press only RButton and define the area.
; Whenever the LButton is pressed additionally, the area can be moved.
; When RButton is released, the coordinates are displayed.
Rbutton:: ;FirstKey
ToolTip,% SelectArea("ms",SecondKey:="LButton") ;ms = CoordMode Screen
Return
SelectArea(Options:="",SecondKey:="")
{ ; from Learning one, slightly modified
/*
Returns selected area. Return example: 22|13|243|543
Options: (White space separated)
- c color. Default: Blue.
- t transparency. Default: 50.
- g GUI number. Default: 99.
- m CoordMode. Default: s. s = Screen, r = Relative
Examples: SelectArea() , SelectArea("cLime t100 g55 mr")
*/
CoordMode, Mouse, Relative
MouseGetPos, rMX, rMY
CoordMode, Mouse, Screen
MouseGetPos, MX, MY
loop, parse, Options, %A_Space%
{
Field := A_LoopField
FirstChar := SubStr(Field,1,1)
if FirstChar contains c,t,g,m
{
StringTrimLeft, Field, Field, 1
%FirstChar% := Field
}
}
c := (c = "") ? "Blue" : c, t := (t = "") ? "50" : t, g := (g = "") ? "99" : g , m := (m = "") ? s : m
Gui %g%: Destroy
Gui %g%: +AlwaysOnTop -caption +Border +ToolWindow +LastFound
WinSet, Transparent, %t%
Gui %g%: Color, %c%
;Hotkey := RegExReplace(A_ThisHotkey,"^(\w* & |\W*)")
RegExMatch(A_ThisHotkey, "\W$|\w*$", Hotkey)
While, (GetKeyState(Hotkey, "p"))
{
Sleep, 10
MouseGetPos, MXend, MYend
IF GetKeyState(SecondKey,"P")
MX += MXend - MXOld, MY += MYend - MYOld
w := Abs(MX - MXend), h := Abs(MY - MYend)
X := Min(MX, MXOld:=MXend), Y := Min(MY, MYOld:=MYend)
Gui %g%: Show, x%X% y%Y% w%w% h%h% NA
}
Gui %g%: Destroy
if m = s ; Screen
{
MouseGetPos, MXend, MYend
If (MX > MXend)
temp := MX, MX := MXend, MXend := temp
If (MY > MYend)
temp := MY, MY := MYend, MYend := temp
Return MX "|" MY "|" MXend "|" MYend
}
else ; Relative
{
CoordMode, Mouse, Relative
MouseGetPos, rMXend, rMYend
If (rMX > rMXend)
temp := rMX, rMX := rMXend, rMXend := temp
If (rMY > rMYend)
temp := rMY, rMY := rMYend, rMYend := temp
Return rMX "|" rMY "|" rMXend "|" rMYend
}
}
Re: How can I get the coordinates, width, and height of the area that I want to use for Imagesearch?
@Rohwedder Thank you for the awesome script. I just don't know how to use any of those hotkeys, c, t , g, m. What is GUI number?
Re: How can I get the coordinates, width, and height of the area that I want to use for Imagesearch?
c, t, g, m are not Hotkeys but options of this slightly modified function of Learning one.
https://www.autohotkey.com/board/topic/57646-function-selectarea/
The effect of these options is described in the notes:
Returns selected area. Return example: 22|13|243|543
Options: (White space separated)
- c color. Default: Blue.
- t transparency. Default: 50.
- g GUI number. Default: 99.
- m CoordMode. Default: s. s = Screen, r = Relative
https://www.autohotkey.com/board/topic/57646-function-selectarea/
The effect of these options is described in the notes:
Returns selected area. Return example: 22|13|243|543
Options: (White space separated)
- c color. Default: Blue.
- t transparency. Default: 50.
- g GUI number. Default: 99.
- m CoordMode. Default: s. s = Screen, r = Relative
Re: How can I get the coordinates, width, and height of the area that I want to use for Imagesearch?
Adding whatever "kill switch"-option might make sense as opening the script's context menu via right-click for exiting the script seems not possible that way. (task manager to the rescue).
Re: How can I get the coordinates, width, and height of the area that I want to use for Imagesearch?
Sorry, that was just an old (unfinished) snippet. Of course it is allowed to decorate RButton with modifiers.
E.G.:And another FirstKey is also possible:
E.G.:
Code: Select all
; First press Win + RButton, leave RButton pressed and define the range.
; Whenever the LButton is pressed additionally, the area can be moved.
; When RButton is released, the coordinates are displayed.
#Rbutton:: ;FirstKey
ToolTip,% SelectArea("ms",SecondKey:="LButton") ;ms = CoordMode Screen
Return
Code: Select all
#q:: ;FirstKey
Re: How can I get the coordinates, width, and height of the area that I want to use for Imagesearch?
@Rohwedder Can you make your script copy the measurements to the clipboard, change the | to ,, and display in a MsgBox and not a ToolTip. Thanks bro.
Re: How can I get the coordinates, width, and height of the area that I want to use for Imagesearch? Topic is solved
This current version could:
Code: Select all
; First press Win + RButton, leave RButton pressed and define the range
; Whenever the LButton is pressed additionally, the area can be moved.
; When RButton is released, the diagonal coordinates are displayed.
#RButton::MsgBox,% ClipBoard := SelectArea("ms", "LButton", ",")
; RButton = FirstKey
; ms = CoordMode Screen
; LButton = SecondKey
SelectArea(Options:="", SecondKey:="", Coord_Separator:="|")
{ ; from Learning one, modified by Rohwedder 11.07.2022
; https://www.autohotkey.com/board/topic/57646-function-selectarea/
; Returns the diagonal coordinates of the selected area
; Example with default Coord_Separator: 22|13|243|543
; Options: (White space separated)
; - c color. Default: Blue.
; - t transparency. Default: 50.
; - g GUI number. Default: 99.
; - m CoordMode. Default: s. s = Screen, r = Relative
; Examples: SelectArea() , SelectArea("cLime t100 g55 mr")
Loop, Parse, Options, %A_Space%
If InStr("ctgm", FirstChar := SubStr(A_LoopField, 1, 1))
%FirstChar% := SubStr(A_LoopField, 2)
c:=(c="")?"Blue":c, t:=(t="")?"50":t, g:=(g ="")?"99":g
CoordMode, Mouse, Relative
MouseGetPos, XR, YR
CoordMode, Mouse, Screen
MouseGetPos, MX, MY
XR -= MX, XR *= m := m = "r", YR -= MY, YR *= m
Gui %g%: Destroy
Gui %g%: +AlwaysOnTop -caption +Border +ToolWindow +LastFound
WinSet, Transparent, %t%
Gui %g%: Color, %c%
RegExMatch(A_ThisHotkey, "\W$|\w*$", Hotkey)
While, GetKeyState(Hotkey, "P")
{
Sleep, 10
MouseGetPos, MXend, MYend
IF GetKeyState(SecondKey, "P")
MX += MXend - MXold, MY += MYend - MYold
W := Abs(MX - MXend), H := Abs(MY - MYend)
X := Min(MX, MXold:=MXend), Y := Min(MY, MYold:=MYend)
Gui %g%: Show, x%X% y%Y% w%W% h%H% NA
}
Gui %g%: Destroy
MouseGetPos, MXend, MYend
Return, Min(MX,MXend)+XR Coord_Separator Min(MY,MYend)+YR
. Coord_Separator Max(MX,MXend)+XR Coord_Separator Max(MY,MYend)+YR
}
Re: How can I get the coordinates, width, and height of the area that I want to use for Imagesearch?
I don't know how to use the options, specifically ; - m CoordMode. Default: s. s = Screen, r = Relative
Re: How can I get the coordinates, width, and height of the area that I want to use for Imagesearch?
The example on the next line shows you:
Code: Select all
SelectArea("cLime t100 g55 mr")