Code archives/User Input/Simulate mouse click

This code has been declared by its author to be Public Domain code.

Download source code

Simulate mouse click by Andres2007
Simulate left mouse click where you want to.
Function SimulateMouseClick(x%, y%)
	cur_x% = MouseX():cur_y% = MouseY()
	api_SetCursorPos(x%, y%)
	api_mouse_event($0201, 0, 0, 0, 0)
	api_mouse_event($0202, 0, 0, 0, 0)
	api_SetCursorPos(cur_x%, cur_y%)
End Function

Comments

jfk EO-111102007
Sometimes useful. Tho, decls are missing, for those who are not so familar with the API stuff.


blade0072007
ya im not familar with the API stuff


ZJP2007
Just create a file named for example "mouse_api.decls" and put it in the blitz3d userlibs directory.

mouse_api.decls

.lib "user32.dll"
api_SetCursorPos% (x%, y%) : "SetCursorPos"
api_mouse_event (dwFlags%, dx%, dy%, cButtons%, dwExtraInfo%) : "mouse_event"



Wings2008
well i go code my wow bot then ... so i can code in bb while loling my account on wow :) )


blade0072008
this is great!

can you simulate the right mouse button too?


AJ002002009
Thanks, this works good!


blade0072009
Hey I figured out how to do the right mouse button too
Function SimulateRightMouseClick(x%, y%)
	cur_x% = MouseX():cur_y% = MouseY()
	api_SetCursorPos(x%, y%)
	api_mouse_event($0204, 0, 0, 0, 0)
	api_mouse_event($0205, 0, 0, 0, 0)
	api_SetCursorPos(cur_x%, cur_y%)
End Function



Andres2010
I've noticed that
api_mouse_event(2, 0, 0, 0, 0)
api_mouse_event(4, 0, 0, 0, 0)

does a "better" clicking, the other or older one had some glitches, i think it didn't very good work on key-up function. Atleast it didn't work in Morrowind. But the decimal numbers worked fine.


Code Archives Forum