I have searched the KM documentation, the wiki, and this forum, and could not find anything that clearly stated how to access/use the data in the variable set by the Find Image on Screen action.
The above link states:
stores the rectangle containing the match followed by the fuzz of the match (0-100), ie, (left,top,width,height,fuzz), in a variable.
OK, great. But if I want to use that data, like move the mouse & click in the center of the image using the coordinates in that variable, how do I do that?
Let's say that the variable ImageLoc was set.
How do I use ImageLoc variable to set the Move or Click Mouse action to click on the image center?
BTW, I know I can use the Move or Click Mouse action based on an image, but due to other issues I need to separate finding the image from clicking on it.
Thanks, Peter.
But I'm not sure I understand what you mean by that.
Why do you add 12 to the X and Y?
How would the user know to use the ".x" and ".y" notation? I didn't see that anywhere in the docs?
As Peter mentioned the action only provides coordinates for the TOP, LEFT corner of the image.
If for instance you're tying to click the image the top, left corner might not work, so you add some padding to push the cursor into the image before clicking.
Variable values are text, but they can contain comma separated numbers, and can then be accessed as arrays (eg Variable Name[1]). Mouse positions, window frames and the like can then be stored and manipulated in variables, and you can access the fields with "struct" like forms like Variable Name.width (field names include: x, y, left, right, top, bottom, width, height, midx, midy, and fuzz).
Thanks Chris. But when the user is viewing the documentation for Find Image on Screen action, there is NO mention of how the variable is structured nor any reference to "Variable" or "Calculations"
It would be most helpful if the documentation provided a bit more information, like:
The image location stored in the variable may be referenced as a structure in other actions like Move and Click Mouse using the following notation:
Assuming the variable is named "ImageLoc":
ImageLoc.x -- Horizontal position of upper left corner
ImageLoc.y -- Veritcal position of upper left corner
Thanks, Peter. Please see my suggestion above for changes to the documentation that would be very helpful.
Also, it is not very clear that the "Calculate" command is needed to display the structure of the ImageLoc variable. I finally figured it out, but it seems like this should work in a "Display Text" action:
%Variable%ImageLoc.x%
but it does not.
You have to use the "Calculate" command:
%Calculate%ImageLoc.x%
What is confusing, and IMO inconsistent, is that the "Calculate" command is necessary in the "Display Text" action, but is NOT used in the "Move and Click" action.
Of course I know you know this -- I'm just stating it for other readers who may not know, like me.
Its not a question of being inconsistent, its a question of understanding the difference between text fields and numeric fields. This is a fundamental concept in Keyboard Maestro - you can do basic things in Keyboard Maestro without understanding text tokens, functions, and text fields, but if you want to get much further, understanding the two kinds is essential. In numeric fields, you write formulas without adornments (eg "Variable * WINDOWCOUNT()"). In text fields, you obviously need some sort of marker to tell whether "Variable" means the value of the variable or the text of the variable, hence text tokens.
You're right that this is something that needs to be learnt.