The Wiki for Tale 4 is in read-only mode and is available for archival and reference purposes only. Please visit the current Tale 11 Wiki in the meantime.

If you have any issues with this Wiki, please post in #wiki-editing on Discord or contact Brad in-game.

Difference between revisions of "User:Cegaiel/Macros/GetMousePosition"

From A Tale in the Desert
Jump to navigationJump to search
 
(2 intermediate revisions by the same user not shown)
Line 9: Line 9:
 
<BR>
 
<BR>
 
I mainly added the color gathering portion in case I want to write a macro with the PixelSearch in autohotkey.
 
I mainly added the color gathering portion in case I want to write a macro with the PixelSearch in autohotkey.
 +
 +
 +
Anytime you hit F2, it does two things, causes a popup which freezes the info, and also saves it to your clipboard:
 +
 +
[[Image:Cegcode2.jpg]]
 +
 +
 +
The purpose of gathering the screen center and the offset (screen center - mouse position) is so that so that you can easily add locations of buttons on the screen, that will work at all screen resolutions (instead of hardcoding an x,y position.  I'll explain that below...
 +
 +
  
  
Line 41: Line 51:
  
 
To see a simple, small macro of this function in action, look at my [[User:Cegaiel/Macros/PopUpCloser | Pop up box clicker]] macro. It looks for the yellowish color that occurs in a popup box (ie too tired) and clicks the OK button anytime it occurs.
 
To see a simple, small macro of this function in action, look at my [[User:Cegaiel/Macros/PopUpCloser | Pop up box clicker]] macro. It looks for the yellowish color that occurs in a popup box (ie too tired) and clicks the OK button anytime it occurs.
 +
 +
 +
 +
<B>Example on how to configure button locations for all resolutions</b> (ie an OK button on a popup, or the Max button with gather water, etc)
 +
 +
 +
The X position of a button rarely changes from resolution to resolution, but the Y position always changes.
 +
 +
 +
The buttons are based off the center of the screen.  Here is an example of finding the center position of the screen:
 +
 +
<pre>
 +
WinGetActiveStats, win_Title, Xmax, Ymax, win_Xpos, win_Ypos
 +
CenterX := Floor(Xmax/2)
 +
CenterY := Floor(Ymax/2)
 +
</pre>
 +
 +
 +
So, based on the second screenshot of the popup, my center (1280x1024) is 644,501.  The first number rarely changes, so we need to find the offset of the Y position.  In the popup screenshot above, I hit F2 on the Max button of gathering water. As you see, X did not change. But Y is not correct. Y is 57 more coordinates that the center of screen.  So now I would change the above code to this:
 +
 +
 +
<pre>
 +
WinGetActiveStats, win_Title, Xmax, Ymax, win_Xpos, win_Ypos
 +
CenterX := Floor(Xmax/2)
 +
CenterY := Floor(Ymax/2) + 57
 +
</pre>
 +
 +
This code should now find the Max button at any screen resolution.
 +
 +
 +
So instead of hardcoding <b>Click 644,508 I use the above code to work at any resolution.

Latest revision as of 03:22, 26 October 2010

Get Mouse Position and Color (Autohotkey)

Just launch the script and it will show you this tooltip wherever you move the mouse. All the information on tooltip updates in realtime as you move the mouse.

Cegcode1.jpg


I wrote this in case I need to find the mouse position that I need to click on or if I need to find the color of where my mouse is hovering.
I mainly added the color gathering portion in case I want to write a macro with the PixelSearch in autohotkey.


Anytime you hit F2, it does two things, causes a popup which freezes the info, and also saves it to your clipboard:

Cegcode2.jpg


The purpose of gathering the screen center and the offset (screen center - mouse position) is so that so that you can easily add locations of buttons on the screen, that will work at all screen resolutions (instead of hardcoding an x,y position. I'll explain that below...



Get Code!


Example code for finding color:

This will search for the color 0xE1D4AC (same as html code #E1D4AC) at mouse position 540,341.


PixelGetColor, color, 540, 341, RGB
if color = 0xE1D4AC
{
MsgBox, Color detected 
}else{
Msgbox, Color not found

Or to search for color: 0xE1D4AC from x,y to x,y (No, they do not need to be the same coordinates, The first x,y is upper left corner, the 2nd x,y is bottom right corner, of an area/rectangle). But since I used the same x,y on both sides, it will only look at one coordinate for the color. Normally you'd use something like 540,341 as upper left corner to search and 600,400 as the lower right corner to search. The #25 means to look for the color within 25 shades. So in this case, it doesn't need to find the color exactly, just fairly close.

PixelSearch, Px, Py, 540, 341, 540, 341, 0xE1D4AC, 25, Fast|RGB
if ErrorLevel = 0
{
MsgBox, Color detected 
}else{
Msgbox, Color not found
}

To see a simple, small macro of this function in action, look at my Pop up box clicker macro. It looks for the yellowish color that occurs in a popup box (ie too tired) and clicks the OK button anytime it occurs.


Example on how to configure button locations for all resolutions (ie an OK button on a popup, or the Max button with gather water, etc)


The X position of a button rarely changes from resolution to resolution, but the Y position always changes.


The buttons are based off the center of the screen. Here is an example of finding the center position of the screen:

WinGetActiveStats, win_Title, Xmax, Ymax, win_Xpos, win_Ypos 
CenterX := Floor(Xmax/2)
CenterY := Floor(Ymax/2)


So, based on the second screenshot of the popup, my center (1280x1024) is 644,501. The first number rarely changes, so we need to find the offset of the Y position. In the popup screenshot above, I hit F2 on the Max button of gathering water. As you see, X did not change. But Y is not correct. Y is 57 more coordinates that the center of screen. So now I would change the above code to this:


WinGetActiveStats, win_Title, Xmax, Ymax, win_Xpos, win_Ypos 
CenterX := Floor(Xmax/2)
CenterY := Floor(Ymax/2) + 57

This code should now find the Max button at any screen resolution.


So instead of hardcoding Click 644,508 I use the above code to work at any resolution.