Code: Select all
a1000,0,1200,1500
Code: Select all
a1000,0,1200,1500
Code: Select all
area := "a1000,0,1200,1500"
Gui, -Caption -Border +HwndID
Gui, Color, Red,
RegExMatch(area, "(\d+),(\d+),(\d+),(\d+)", a)
Gui, Show, x%a1% y%a2% w%a3% h%a4%
WinSet, Transparent, 150, ahk_id %ID%
return
Esc::ExitApp
Regarding this toggle, just wondering if the modifiers at the end apply to only the latter image instead of BOTH images? I tried adding modifiers to the front image but it is not allowed:boiler wrote: ↑22 Feb 2021, 11:02...or a more compact version:Code: Select all
F11::FindClick((Toggle := !Toggle) ? "C:\MyImage1.png" : "C:\MyImage2.png", "a,,,+500 o12")
Code: Select all
Toggle := !Toggle
FindClick("E:\Dropbox\Screenshots\AutoHotkey_2021-03-05_17-" . (Toggle ? "29-56.png" : "30-36.png"), Toggle ? "o30" : "o60")
I see. If both files are in different directories, what is the right way to write it then?boiler wrote: ↑07 Mar 2021, 20:28Each parameter is its own expression. You can't have one ternary expression span both parameters (the file name parameter and the options parameter). If you want both to be based on the toggle value, then you need a separate ternary expression for each:Code: Select all
Toggle := !Toggle FindClick("E:\Dropbox\Screenshots\AutoHotkey_2021-03-05_17-" . (Toggle ? "29-56.png" : "30-36.png"), Toggle ? "o30" : "o60")
It would be like this:milkygirl90 wrote: ↑ If both files are in different directories, what is the right way to write it then?
Code: Select all
Toggle := !Toggle
FindClick(Toggle ? "E:\Dropbox\Screenshots\AutoHotkey_2021-03-05_17-29-56.png" : "E:\Dropbox\Screenshots\AutoHotkey_2021-03-05_17-30-36.png", Toggle ? "o30" : "o60")
Code: Select all
if (Toggle := !Toggle)
FindClick("E:\Dropbox\Screenshots\AutoHotkey_2021-03-05_17-29-56.png", "o30")
else
FindClick("E:\Dropbox\Screenshots\AutoHotkey_2021-03-05_17-30-36.png", "o60")
Code: Select all
; at top of script:
File1 := "E:\Dropbox\Screenshots\AutoHotkey_2021-03-05_17-29-56.png"
File2 := "E:\Dropbox\Screenshots\AutoHotkey_2021-03-05_17-30-36.png"
; ...
Toggle := !Toggle
FindClick(Toggle ? File1 : File2, Toggle ? "o30" : "o60")
I see. Thanks for the explanation. If the only variable is the drive letter, and I have hundreds of FindClick code nested inside #IfWinActive of various applications, is there a way to globally define the drive letter as being C or D or E? I know I should have parked my screenshots folder with the script, but it's now too late I guessboiler wrote: ↑08 Mar 2021, 05:13It would be like this:milkygirl90 wrote: ↑ If both files are in different directories, what is the right way to write it then?Code: Select all
Toggle := !Toggle FindClick(Toggle ? "E:\Dropbox\Screenshots\AutoHotkey_2021-03-05_17-29-56.png" : "E:\Dropbox\Screenshots\AutoHotkey_2021-03-05_17-30-36.png", Toggle ? "o30" : "o60")
But the advantages of more compact code and readability from using ternary expressions are getting lost with it getting so long, so you might as well just go with a traditional if/else with separate statements:Code: Select all
if (Toggle := !Toggle) FindClick("E:\Dropbox\Screenshots\AutoHotkey_2021-03-05_17-29-56.png", "o30") else FindClick("E:\Dropbox\Screenshots\AutoHotkey_2021-03-05_17-30-36.png", "o60")
Or you could assign the file paths to variables and use the variable names in the function call rather than the literal strings:Code: Select all
; at top of script: File1 := "E:\Dropbox\Screenshots\AutoHotkey_2021-03-05_17-29-56.png" File2 := "E:\Dropbox\Screenshots\AutoHotkey_2021-03-05_17-30-36.png" ; ... Toggle := !Toggle FindClick(Toggle ? File1 : File2, Toggle ? "o30" : "o60")
It’s not too late. There are various ways to modify the script to replace the hard-coded drive letter with the proper syntax to implement a variable. You could use your editor to do a global find/replace to modify the appropriate lines of code as necessary. Depending on the details, you probably need to use an editor with RegEx find/replace capability (such as Notepad++), or you could write a script to modify the text of the script.milkygirl90 wrote: ↑ If the only variable is the drive letter, and I have hundreds of FindClick code nested inside #IfWinActive of various applications, is there a way to globally define the drive letter as being C or D or E? I know I should have parked my screenshots folder with the script, but it's now too late I guess
Code: Select all
If ImageFoundUsingFindClick
Do A
Else
Do B
Code: Select all
if FindClick(...)
Do A
else
Do B
Code: Select all
f12::
IF FindClick("E:\Dropbox\Screenshots\AutoHotkey_2021-03-12_22-03-37.png", "o60")
Msgbox, tested
else
return
Code: Select all
f12::
MsgBox, % FindClick("E:\Dropbox\Screenshots\AutoHotkey_2021-03-12_22-03-37.png", "n0 o60")
return
Code: Select all
#If WinActive("Gmail")
!IF FindClick("E:\Dropbox\Screenshots\AutoHotkey_2021-03-15_07-57-03.png", "n0 o60") ;Gmail Email View. If I don't see my Gmail avatar, then the hotkeys below will be valid
{
Del::#
z::k
x::msgbox, test
y::MsgBox, % FindClick("E:\Dropbox\Screenshots\AutoHotkey_2021-03-15_07-57-03.png", "n0 o60")
}
return
Hmm.. I don't really understand the 2 statements above and have started a separate thread.
Code: Select all
Home::
FindClick("E:\Dropbox\Screenshots\chrome_2021-02-26_09-38-21.png", "o60") ; Click Align
Sleep 50
FindClick("E:\Dropbox\Screenshots\chrome_2021-02-26_09-39-06.png", "o60") ;Align Middle
Sleep 100
FindClick("E:\Dropbox\Screenshots\chrome_2021-02-26_09-38-21.png", "o60") ;Align
Sleep 100
FindClick("E:\Dropbox\Screenshots\chrome_2021-02-26_09-46-40.png", "o60") ;Align Top
return
Code: Select all
o – ImageSearch Options
What to give comma-delimited string of imagesearch options
Description The optional parameters for ImageSearch, as shown in the AutoHotkey documentation. Use a comma to separate options instead of a space. You may omit the asterisk (*). For example: oTransBlack,20 makes black transparent and allows 20 shades of variation.
a – Search Area Modifications What to give x[,y,w,h] or mn
Description Region within which to search for the image. Indicate either of the following: 1) A comma-delimited list in the format x,y,w,h. List items may be blank or absent to leave that value unchanged. Coordinates are relative to the window if r is used. For w and h, use + and - to indicate a change to the normal endpoint (depending on a, either the edge of the screen or active window). For instance, a,,-300 will search the entire screen (or window if r is used) except for the last 300 pixels of the right side – the width of the search area has been reduced by 300. 2) The letter m and then a number to search a square region centered at the cursor position and with a width and height twice that number.
r – Relative to Window Coords
What to give window title criteria OR a window hwnd
Description The search area becomes the area of the given window instead of the entire screen area. This is useful when scanning for an element which only appears on a particular window – reducing the search area improves performance. Use of the a option in conjunction with r will apply these offsets to the window coordinates.
x – X Offset
What to give any integer Description This many pixels will be incremented to the click coordinates before clicking. A positive x value will click left of the image, a negative value will click to the right. This change will also show up in the string that is returned by the function and the coordinates stored in the ByRef variables.
y – Y Offset
What to give any integer Description This many pixels will be incremented to the click coordinates before clicking. A positive y value will click below the image, and a negative value will click above it. This change will also show up in the string that is returned by the function and the coordinates stored in the ByRef variables.
n – Number of clicks (No click)
What to give any integer Description The number of times to click on each image. Indicate 0 (the user default) to do no clicking whatsoever and just return the coordinates of the found image(s). In this sense, specifying just n is like saying “no click”. Without clicks, the m, Sleep, and k options are irrelevant, however, the x and y values will still be added to the output coordinates.
e – Find Every Image
What to give positive fraction between 0 and 1
Description If this option is nonblank then FindClick will find (and click) EVERY instance found. This means that after any successful ImageSearch execution the script will queue up a new call of ImageSearch which represents the screen area left unsearched by the first call. (Note that this therefore makes FindClick slower for any use in which you don’t expect to find more than one image.) The value of e signifies the overlap between search areas, in terms of the fraction of the image width and height. Overlap should normally be around 0.9 except if the image is uniform throughout, e.g. a 10x10 square image containing mostly white pixels. The t, d, and Count options all require the “find every image” behavior as part of their execution and so using any of these other options implies e, however, you may still specify a custom value for e to change the overlap for these other behaviors.
w – Wait until image is found
What to give number of milliseconds [, number of milliseconds]
Description If the image is not found, the function will wait this many milliseconds for it to appear before returning. You may add a comma and then a second number which indicates the delay in milliseconds between subsequent ImageSearches. For example 2000,50 means the function will look for the image every 50ms until either the image is found or 2000ms elapse, for a maximum of 40 ImageSearch operations. If omitted, this delay will be the smaller of either the wait time divided by 10 or 100ms.
dx – Diagnostic Mode
What to give comma delimited list of diagnostic mode options
Description Will produce an AutoHotkey GUI before the function completes showing a step-by-step history of how the function executed. The value of the string passed to the dx option may be used to send certain flags to the debugger GUI before it displays. For more info on this see the section on the FindClick debugger.
k – Keystroke(s)
What to give key to send (in the same format as the AutoHotkey Send command) Description Indicate the keys to press (if any) when each image is found. k can include multiple keypresses and even non-mouse keys, for instance, ^{Space}. If m (SendMode) is ControlClick then the format is different (see the ControlClick documentation) and a left click will be assumed if an incorrect k is given.
Stay – Do not restore mouse What to give true or false (1 or 0)
Description Normally after any clicks executed by FindClick the mouse will be immediately returned to its initial location. If Stay is true then the mouse will NOT return to its original position after FindClick finishes.
Count – Return found count
What to give true or false (1 or 0)
Description If Count is true then the function will return the number of items found instead of their
coordinates. e is assumed if absent.
d – Direction Of Search
What to give left, right, bottom, or the first letter of any of these words
Description This setting attempts to emulate the mode of PixelSearch where you can search from right to left
or top to bottom – for instance, specifying Bottom will find the image closest to the bottom of
the search area. However, to accomplish this the script needs to first find every image and then
choose the coordinate pair that is furthest in the requested direction, making it a timeconsuming
process.
m – SendMode
What to give event, play, input, default, controlclick, or the first letter of any of these words
Description The send mode (or first letter thereof) to use for clicks, i.e. Input, Play, or Event. Specify
ControlClick (or c) to use a controlclick instead of a simulated keystroke. If m is blank or the
letter d (for default), the current SendMode will be used.
Func – Function Callout
What to give the name of a function in the script
Description Each time an image is found, instead of clicking on the image or executing keystrokes the given
function will be called. The function must accept at least two parameters: the x-coordinate of the
image will be passed in the first parameter, and the y-coordinate will be passed in the second
parameter. Note that any thread settings such as CoordMode that are changed within the
function will carry over to FindClick when the function is done.
Sleep – Sleep between clicks
What to give any number of milliseconds
Description Number of milliseconds to sleep between each click if n > 1 or e and multiple images found.
t – Image Tracking
What to give percent OR number of pixels
Description This option is used to improve performance if an image will be found nearby where its last
location. The script will first search nearby the last found position and if it is not found there then
the rest of the area will be searched. Indicate a percentage to search within that percentage of
the search area in each direction. For instance, the string 20% will first search a box that begins
20% of the distance between the starting x position and the last found x position, and likewise
for the other three directions. Indicating a number will simply search a box that many pixels from
the last found area before searching the rest of the s area. Indicate 0 to search EXACTLY the last
found location first. If t is negative (including -0) then it will ONLY search in the region
requested, and will not go on to search the rest of the screen if the image is not found there.
Silent – No Dialogs
What to give true or false (1 or 0)
Description Instead of displaying an error dialog when an error prevents the function from executing
properly (for instance, if the image file is not found), it will silently return a blank string and set
the ErrorLevel to the error message. The errors concerned should not appear during normal
execution and so Silent is generally not recommended.
Center – Start at center of image
What to give true or false (1 or 0)
Description If Center is true then clicks will occur at the center of the image, i.e. its found position plus half
its width and half its height. The x and y options treat this as 0, 0 – for instance, by default an x
of 2 will click 2 pixels to the right of the image center. Indicate false to instead start at the top
left corner of the image.
Delim – Delimiter for multiple images
What to give any character or characters
Description If e is used and multiple images are found then each image’s info is separated by this character(s)
in the returned string. The format of the image info is determined by the value of f.
f – Format of output string
What to give template string that includes CharX and/or CharY and/or CharN characters
Description The given string represents a template into which image x-coordinate, y-coordinate, and instance
number will be substituted. Each time an image is found, the CharX, CharY, and CharN
characters will be replaced with these values. The final string is returned by the function. See the
examples section of the documentation for an example.
CharX – Character spaceholder for x-coordinate
What to give any character
Description Any instance of this character, if present, in the string given for f will be replaced with the
image’s x-coordinate.
CharY – Character spaceholder for y-coordinate
What to give any character
Description Any instance of this character, if present, in the string given for f will be replaced with the
image’s y-coordinate.
CharN – Character spaceholder for image instance number
What to give any character
Description Any instance of this character, if present, in the string given for f will be replaced with the order
in which the image was found among all images found. This character is only relevant when e is
being used and is therefore not normally included in f.
Return to “Scripts and Functions (v1)”
Users browsing this forum: pafec and 105 guests