Is there a way to make mouse coordinates relative to the game window, so 0,0 would be the top left corner of the game window? AutoIt had a mode that was relative to the window in focus like that, and that what I found most useful.
I know I could calculate roughly where I want the mouse to be, but when the operating system is running resolutions of different aspect ratios it gets goofy.
Possible to make mouse coordinates relative to window?
Forum rules
This is a sub-forum for things specific to MicroMacro.
This is not the place to ask questions about the RoM bot, which uses MicroMacro. There is a difference.
This is a sub-forum for things specific to MicroMacro.
This is not the place to ask questions about the RoM bot, which uses MicroMacro. There is a difference.
- Administrator
- Site Admin
- Posts: 5318
- Joined: Sat Jan 05, 2008 4:21 pm
Re: Possible to make mouse coordinates relative to window?
Yes, there is. Through simple math, too.
First, we need to get the position of the window. This is the position of the client region (the actual usable part of the window; does not include title bar and such) as is offset from your screen.
We will need to update wx and wy each frame. Keep this in mind. This is so that if you move the window, it won't be using old position values and throwing your mouse off.
Now, we can use setMouse() to position the mouse at 0,0 in the client region of our specific window.
Notice I am adding 0, but it doesn't really do anything. It is not necessary since we're going to 0,0, but if we wanted, say, 10, 20, we can replace the 0s with 10 and 20.
In reverse, we can get the position of the mouse inside our window as well.
If we just want to use the 'on top' window at all times, we can use foregroundWindow().
First, we need to get the position of the window. This is the position of the client region (the actual usable part of the window; does not include title bar and such) as is offset from your screen.
Code: Select all
local win = findWindow("MyWindow");
local wx,wy = windowRect(win);
Now, we can use setMouse() to position the mouse at 0,0 in the client region of our specific window.
Code: Select all
setMouse(wx + 0, wy + 0);
In reverse, we can get the position of the mouse inside our window as well.
Code: Select all
local mx,my = mouseGetPos();
mx = wx - mx;
my = wy - my;
-- mx and my are now the position of the mouse inside our window.
Code: Select all
local wx,wy = windowRect(foregroundWindow());
mouseSet(wx + 10, wy + 20); -- forcefully set to 10,20 in the window that's on top
Who is online
Users browsing this forum: No registered users and 0 guests