virtual mouse usage

Discuss, ask for help, share ideas, give suggestions, read tutorials, and tell us about bugs you have found with MicroMacro in here.

Do not post RoM-Bot stuff here. There is a subforum for that.
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.
Post Reply
Message
Author
User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

virtual mouse usage

#1 Post by lisa » Sun Dec 06, 2015 8:59 pm

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 ;)
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

User avatar
BlubBlab
Posts: 948
Joined: Fri Nov 30, 2012 11:33 pm
Location: My little Pony cafe

Re: virtual mouse usage

#2 Post by BlubBlab » Sun Dec 06, 2015 9:20 pm

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 :D

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

User avatar
BlubBlab
Posts: 948
Joined: Fri Nov 30, 2012 11:33 pm
Location: My little Pony cafe

Re: virtual mouse usage

#3 Post by BlubBlab » Sun Dec 06, 2015 10:23 pm

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 ?

Code: Select all

	{"setVirtualPosition", Mouse_lua::setVirtualPosition},
	{"getVirtualPosition", Mouse_lua::getVirtualPosition},
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.
Jack-of-all-trades, but master-of-only of a few :D

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

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: virtual mouse usage

#4 Post by lisa » Sun Dec 06, 2015 10:44 pm

Code: Select all

{"setVirtualPosition", Mouse_lua::setVirtualPosition},
   {"getVirtualPosition", Mouse_lua::getVirtualPosition},
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.
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

User avatar
BlubBlab
Posts: 948
Joined: Fri Nov 30, 2012 11:33 pm
Location: My little Pony cafe

Re: virtual mouse usage

#5 Post by BlubBlab » Sun Dec 06, 2015 11:14 pm

lisa wrote:

Code: Select all

{"setVirtualPosition", Mouse_lua::setVirtualPosition},
   {"getVirtualPosition", Mouse_lua::getVirtualPosition},
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.
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.

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 :D

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

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: virtual mouse usage

#6 Post by lisa » Mon Dec 07, 2015 3:08 am

Well for now I am using this and it will probably be good enough to do the job.

Code: Select all

			wx, wy, ww, wh = window.getRect(win)
			local x,y = mouse.getPosition()
			clickw=x-wx-8
			clickh=y-wy-30
So it uses the windows position on screen and the mouse position on screen to adjust for the cords in window to be used.
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

User avatar
Administrator
Site Admin
Posts: 5306
Joined: Sat Jan 05, 2008 4:21 pm

Re: virtual mouse usage

#7 Post by Administrator » Mon Dec 07, 2015 1:22 pm

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).

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: virtual mouse usage

#8 Post by lisa » Mon Dec 07, 2015 3:37 pm

Administrator 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).
Yup that works fine

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

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: virtual mouse usage

#9 Post by lisa » Thu Dec 17, 2015 7:10 pm

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

Code: Select all

						mouse.setVirtualPosition(win, clickw, clickh)
						mouse.virtualPress(win,  key.VK_LMOUSE,true)	
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.

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

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: virtual mouse usage

#10 Post by lisa » Fri Dec 18, 2015 3:20 am

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

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: virtual mouse usage

#11 Post by lisa » Fri Dec 18, 2015 3:35 am

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.
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

User avatar
Administrator
Site Admin
Posts: 5306
Joined: Sat Jan 05, 2008 4:21 pm

Re: virtual mouse usage

#12 Post by Administrator » Fri Dec 18, 2015 12:13 pm

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.

User avatar
BlubBlab
Posts: 948
Joined: Fri Nov 30, 2012 11:33 pm
Location: My little Pony cafe

Re: virtual mouse usage

#13 Post by BlubBlab » Fri Dec 18, 2015 7:51 pm

A bit late but could it be what Lisa wanted something like :

Code: Select all

POINT p;
GetCursorPos( &p );
ScreenToClient( hwnd, &p ) 
or

Code: Select all

ClientToScreen( hwnd, &p ) 
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^^
Jack-of-all-trades, but master-of-only of a few :D

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

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests