virtual mouse usage
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.
virtual mouse usage
Ok so I am trying to use virtual mouse for a game I am playing.
The virtual mouse set position and click work fine the issue I am having is finding the right x,y for the virtual mouse in the window.
There is the get position which tells me the position of mouse in the screen but I can't find an option to get the mouse position in relation to the window I want because virtual mouse cords are set according to the window.
Any chance of a mouse.getpositioninwindow(number hwnd) function
The virtual mouse set position and click work fine the issue I am having is finding the right x,y for the virtual mouse in the window.
There is the get position which tells me the position of mouse in the screen but I can't find an option to get the mouse position in relation to the window I want because virtual mouse cords are set according to the window.
Any chance of a mouse.getpositioninwindow(number hwnd) function
Remember no matter you do in life to always have a little fun while you are at it
wiki here http://www.solarstrike.net/wiki/index.php?title=Manual
wiki here http://www.solarstrike.net/wiki/index.php?title=Manual
Re: virtual mouse usage
Should be easy to implement http://stackoverflow.com/questions/6423 ... r-position
Code: Select all
POINT p;
if (GetCursorPos(&p))
{
//cursor position now in p.x and p.y
}
This returns the cursor position relative to screen coordinates. Call ScreenToClient to map to window coordinates.
if (ScreenToClient(hwnd, &p))
{
//p.x and p.y are now relative to hwnd's client area
}
Jack-of-all-trades, but master-of-only of a few
My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226
My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226
Re: virtual mouse usage
Okay I called them:(need some testing)
/* mouse.getWindowPosition(hwnd)
Returns: number x
number y
Returns the position of the physical mouse cursor, in pixels insode the window.
*/
/* mouse.setWindowPosition(hwnd, number x, number y)
Returns: nil
Attempts to set the physical mouse wheel inside the windows to
the given coordinates. 'x' and 'y' are
specified in pixels.
*/
http://www.mediafire.com/download/9uqa5 ... 22_x64.zip
ups sine I made it quick and dirty i forgor to update the source code..
I will comitt the update on github in a few moments
Besides that what are those functions ?
They look like what Lisa wanted but they don't take an hwnd ??
Edit:
Okay mouse.setWindowPosition(hwnd, number x, number y) seems to be equal to setVirtualPosition but getVirtualPosition seems to lack the hwnd so I don't know what it does.
/* mouse.getWindowPosition(hwnd)
Returns: number x
number y
Returns the position of the physical mouse cursor, in pixels insode the window.
*/
/* mouse.setWindowPosition(hwnd, number x, number y)
Returns: nil
Attempts to set the physical mouse wheel inside the windows to
the given coordinates. 'x' and 'y' are
specified in pixels.
*/
http://www.mediafire.com/download/9uqa5 ... 22_x64.zip
ups sine I made it quick and dirty i forgor to update the source code..
I will comitt the update on github in a few moments
Besides that what are those functions ?
Code: Select all
{"setVirtualPosition", Mouse_lua::setVirtualPosition},
{"getVirtualPosition", Mouse_lua::getVirtualPosition},
Edit:
Okay mouse.setWindowPosition(hwnd, number x, number y) seems to be equal to setVirtualPosition but getVirtualPosition seems to lack the hwnd so I don't know what it does.
Jack-of-all-trades, but master-of-only of a few
My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226
My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226
Re: virtual mouse usage
Code: Select all
{"setVirtualPosition", Mouse_lua::setVirtualPosition},
{"getVirtualPosition", Mouse_lua::getVirtualPosition},
Remember no matter you do in life to always have a little fun while you are at it
wiki here http://www.solarstrike.net/wiki/index.php?title=Manual
wiki here http://www.solarstrike.net/wiki/index.php?title=Manual
Re: virtual mouse usage
If you want the relation then take both and calculate it this sounds for me like you want to move the mouse a bit outside the windows to press X or something like that.lisa wrote:They both work fine, I need the physical mouse position in relation to the window so that I can use setVirtualPosition more easily and accurately.Code: Select all
{"setVirtualPosition", Mouse_lua::setVirtualPosition}, {"getVirtualPosition", Mouse_lua::getVirtualPosition},
Anyway those 2 function I wrote takes and gives only window coordinates which "should be 100% accurate" because windows does the math.
Jack-of-all-trades, but master-of-only of a few
My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226
My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226
Re: virtual mouse usage
Well for now I am using this and it will probably be good enough to do the job.
So it uses the windows position on screen and the mouse position on screen to adjust for the cords in window to be used.
Code: Select all
wx, wy, ww, wh = window.getRect(win)
local x,y = mouse.getPosition()
clickw=x-wx-8
clickh=y-wy-30
Remember no matter you do in life to always have a little fun while you are at it
wiki here http://www.solarstrike.net/wiki/index.php?title=Manual
wiki here http://www.solarstrike.net/wiki/index.php?title=Manual
- Administrator
- Site Admin
- Posts: 5312
- Joined: Sat Jan 05, 2008 4:21 pm
Re: virtual mouse usage
Sorry for the late reply, but yes that is the recommended method. You may want to use the client rect (getClientRect instead of just getRect) so that it will not be affected by differences in Windows title bars (such as from theme settings).
Re: virtual mouse usage
Yup that works fineAdministrator wrote:Sorry for the late reply, but yes that is the recommended method. You may want to use the client rect (getClientRect instead of just getRect) so that it will not be affected by differences in Windows title bars (such as from theme settings).
Code: Select all
wx, wy, ww, wh = window.getClientRect(win)
local x,y = mouse.getPosition()
repairw=x-wx
repairh=y-wy
Remember no matter you do in life to always have a little fun while you are at it
wiki here http://www.solarstrike.net/wiki/index.php?title=Manual
wiki here http://www.solarstrike.net/wiki/index.php?title=Manual
Re: virtual mouse usage
Ok I have an interesting thing I have noticed with the virtual mouse.
I will post all the code I am using at the moment but the thing I have noticed is that 1 virtual mouse press works fine but another seems to move the physical mouse which I can't explain. So one of them the mouse is actually moved to that position and stays there, even if another window has focus it moves the physical mouse to that location.
This part the virtual works fine
This part seems to move the physical mouse, the only real difference I see between the 2 is the keyboard hold in the one that seems to move the physical mouse.
I will post all the code I am using at the moment but the thing I have noticed is that 1 virtual mouse press works fine but another seems to move the physical mouse which I can't explain. So one of them the mouse is actually moved to that position and stays there, even if another window has focus it moves the physical mouse to that location.
This part the virtual works fine
Code: Select all
mouse.setVirtualPosition(win, clickw, clickh)
mouse.virtualPress(win, key.VK_LMOUSE,true)
Code: Select all
if walkhold > 0 then
keyboard.virtualHold(win, key.VK_W)
else
keyboard.virtualRelease(win, key.VK_W)
walk = false
mouse.setVirtualPosition(win, ww/2, wh/2)
mouse.virtualPress(win, key.VK_LMOUSE,true)
end
Code: Select all
local proc, timeLeft, repairtime, walktime, gaptime, step, walkhold, wintable
local go = false
local mine = false
local wx, wy, ww, wh = 0,0,0,0
local win
local waittime = 5
local repairwait = 36000
local walkwait = 60
local logouttime = (60*60*4)
local targetWindowClass = "LWJGL"
local targetWindowName = "*"
local clickw, clickh = 50,50
local procid
function searchForWindow()
--win = window.find(targetWindowName, targetWindowClass)
wintable = window.findList(targetWindowName, targetWindowClass)
for i = 1, #wintable do
if string.find(wintable[i].name, "dle") then
win = wintable[i].hwnd
printf(i.."\n")
end
end
procid = process.findByWindow(win)
proc = process.open(procid)
table.print(wintable)
if( win ) then
printf("window found: 0x%X\n", win)
printf("You can now walk away from the computer!\n")
--printf("0x%x", process.getModuleAddress(procid, "OpenAL64.dll"))
end
end
function getStam()
return process.read(proc, "float", 0x2FDD0464) or 0
end
function macro.init()
repairtime = repairwait
timeLeft = 0
repairtime = 0
walktime = 0
gaptime = 0
walkhold = 0
logtime = 0
win = window.find(targetWindowName, targetWindowClass)
window.setTitle(window.getAppHwnd(),"anti idle")
searchForWindow()
if( not win ) then
printf("You need to have the game running. Start it, focus the window, and press the END key on your keyboard.\n");
end
end
function macro.main(dt)
timeLeft = timeLeft - dt
repairtime = repairtime - dt
walktime = walktime - dt
gaptime = gaptime - dt
walkhold = walkhold - dt
logouttime = logouttime - dt
if go then
if win then
if 0 > logouttime then
--os.execute("TASKKILL /PID " .. procid .. " /F");
--os.execute("\"%windir%\\system32\\shutdown.exe -s -t 30\" ")
--error("Exiting: Auto-logout", 0)
end
if walk then
if walkhold > 0 then
keyboard.virtualHold(win, key.VK_W)
else
keyboard.virtualRelease(win, key.VK_W)
walk = false
mouse.setVirtualPosition(win, ww/2, wh/2)
mouse.virtualPress(win, key.VK_LMOUSE,true)
end
else
if gaptime < 0 and mine and walktime < 0 then
-- move forward
printf("moving forward\n")
walktime = walkwait
gaptime = 2
walkhold = 1
walk = true
end
if gaptime < 0 and timeLeft < 0 then
if 130 > getStam() then
timeLeft = 4
else
mouse.setVirtualPosition(win, clickw, clickh)
mouse.virtualPress(win, key.VK_LMOUSE,true)
timeLeft = waittime
end
gaptime = 1
end
end
end
end
return true;
end
function macro.event(e, data1, data2, data3)
if( e == "keypressed" ) and win == window.getFocusHwnd() then
if( data1 == key.VK_END ) then
window.setTitle(window.getAppHwnd(),"Paused G")
printf("stopping\n")
go = false
end
if( data1 == key.VK_DELETE ) then
window.setTitle(window.getAppHwnd(),"Going G")
printf("going\n")
timeLeft = 0
go = true
end
if( data1 == key.VK_NUMPAD1 ) then
wx, wy, ww, wh = window.getClientRect(win)
local x,y = mouse.getPosition()
clickw=x-wx
clickh=y-wy
end
if( data1 == key.VK_NUMPAD2 ) then
wx, wy, ww, wh = window.getClientRect(win)
local x,y = mouse.getPosition()
repairw=x-wx
repairh=y-wy
end
if( data1 == key.VK_NUMPAD3 ) then
walktime = walkwait
mine = not mine
if mine then printf("mining\n") else printf("not mining\n") end
end
end
end
Remember no matter you do in life to always have a little fun while you are at it
wiki here http://www.solarstrike.net/wiki/index.php?title=Manual
wiki here http://www.solarstrike.net/wiki/index.php?title=Manual
Re: virtual mouse usage
I can't explain it, I did some prints which atleast pointed out I was doing the key held every cycle for 1 second, so I fixed that but still moving the mouse, what really gets me though is according to the prints the mouse is still where it should be after the virtual press. So it is like it does the virtual move and click and then afterwards it moves the physical mouse.
Code: Select all
744.0 351.0 before virtual move
744.0 351.0 before virtual move
moving forward
744.0 351.0 before key held
744.0 351.0 after key released -- after the virtual move and mouse click
622.0 426.0 before virtual move -- 1 second later and this is where the virtual mouse was virtually clicked.
Code: Select all
if walk then
if walkhold > 0 then
if not held then
local x,y = mouse.getPosition()
printf(x.." "..y.." before key held\n")
keyboard.virtualHold(win, key.VK_W)
held = true
end
return true
else
keyboard.virtualRelease(win, key.VK_W)
walk = false
mouse.setVirtualPosition(win, ww/2, wh/2)
mouse.virtualPress(win, key.VK_LMOUSE,true)
local x,y = mouse.getPosition()
printf(x.." "..y.." after key released\n")
held = false
return true
end
else
if gaptime < 0 and mine and walktime < 0 then
-- move forward
printf("moving forward\n")
walktime = walkwait
gaptime = 2
walkhold = 1
walk = true
end
if gaptime < 0 and timeLeft < 0 then
if 130 > getStam() then
timeLeft = 4
else
local x,y = mouse.getPosition()
printf(x.." "..y.." before virtual move\n")
mouse.setVirtualPosition(win, clickw, clickh)
mouse.virtualPress(win, key.VK_LMOUSE,true)
timeLeft = waittime
end
gaptime = 1
end
end
Remember no matter you do in life to always have a little fun while you are at it
wiki here http://www.solarstrike.net/wiki/index.php?title=Manual
wiki here http://www.solarstrike.net/wiki/index.php?title=Manual
Re: virtual mouse usage
Seems to be the game doing it, by clicking a different thing it has reacted differently. I moved a UI thing to the middle so it would be clicking a user interface window instead of an object in game and it no longer had the mouse in middle of screen.
So yeah seems like a game issue.
So yeah seems like a game issue.
Remember no matter you do in life to always have a little fun while you are at it
wiki here http://www.solarstrike.net/wiki/index.php?title=Manual
wiki here http://www.solarstrike.net/wiki/index.php?title=Manual
- Administrator
- Site Admin
- Posts: 5312
- Joined: Sat Jan 05, 2008 4:21 pm
Re: virtual mouse usage
Could very well be the game doing it. ArcheAge did the same. What happens is, when you hold a click to pan the camera, they record the position your mouse was at before you start. Once you release, they reset the position to give the illusion that it never moved.
Re: virtual mouse usage
A bit late but could it be what Lisa wanted something like :
or
I mean I noticed that you can get the position in client or screen but always the coordinates are relative to inside what you asking in very rare cases it could be that you want calculate the screen coordinated from a position inside a client... Hm the only use which this wold have is if you want to check if the cursor is still inside the screen by comparing x and y are >= 0 and then calculate th screen coordinates to do something with it.(but you could always simple ask again about the screen coordinates after this call).
So yeah Lisa should say if this make any help^^
Code: Select all
POINT p;
GetCursorPos( &p );
ScreenToClient( hwnd, &p )
Code: Select all
ClientToScreen( hwnd, &p )
So yeah Lisa should say if this make any help^^
Jack-of-all-trades, but master-of-only of a few
My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226
My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226
Who is online
Users browsing this forum: Ahrefs [Bot] and 24 guests