help needed to automate mouse

BlitzPlus Forums/BlitzPlus Programming/help needed to automate mouse

Rob(Posted 2004) [#1]
Hi there,

I really need some code to automate the mouse. I'd like to be able to tell it to move to x,y and click either button if I want to for the purposes of scripting moves in B+.

The B+ app would not be in focus when this happens.

Thanks in advance
Rob


dan_upright(Posted 2004) [#2]
use your hand you lazy eejit =p


Eikon(Posted 2004) [#3]
You can use the SetCursorPos API for positioning the mouse and Mouse_Event/MouseEventEx can simulate clicks. I can work up an example if needed.


Rob(Posted 2004) [#4]
I would appreciate an example, thanks :)


Eikon(Posted 2004) [#5]
Userlib Entries:
.lib "user32.dll"
SetCursorPos%(x%, y%)
mouse_event%(dwFlags%, dx%, dy%, cButtons%, dwExtraInfo%)

B+ Code:
; //=============================
; // Mouse API Example by Eikon
; //=============================
Desk_W = ClientWidth(Desktop())
Desk_H = ClientHeight(Desktop())

; // [GUI]
Parent = CreateWindow("Mouse API", (Desk_W / 2) - 75, (Desk_H / 2) - 50, 150, 100, 0, 1)
New_X  = CreateTextField(5, 5, 64, 18, Parent, 0)
New_Y  = CreateTextField(75, 5, 64, 18, Parent, 0)
Move   = CreateButton ("Move Mouse", 5, 26, 134, 18, Parent, 1)
Simu   = CreateButton ("Simulate Click", 5, 48, 134, 18, Parent, 1)

SetGadgetText New_X, Desk_W / 2 ; // [Defaults]
SetGadgetText New_Y, Desk_H / 2

; // [Mouse_Event dwFlag Constants]
Const MOUSEEVENTF_ABSOLUTE   = -32768 ; // Use absolute coords
Const MOUSEEVENTF_MOVE       = 1      ; // Trigger move event
Const MOUSEEVENTF_LEFTDOWN   = 2      ; // LMB Down
Const MOUSEEVENTF_LEFTUP     = 4      ; // LMB Up
Const MOUSEEVENTF_RIGHTDOWN  = 8      ; // RMB Down
Const MOUSEEVENTF_RIGHTUP    = 16     ; // RMB Up
Const MOUSEEVENTF_MIDDLEDOWN = 32     ; // MMB Down
Const MOUSEEVENTF_MIDDLEUP   = 64     ; // MMB Up
Const MOUSEEVENTF_WHEEL      = 128    ; // NT Only: Mouse wheel moved, specify amount in dwExtraInfo

; // [Main]
Repeat
	
Select WaitEvent()
	Case $803: End
	Case $401 ; // [Gadget Event]
	Select EventSource()
		Case Move: SetCursorPos Int(TextFieldText(New_X)), Int(TextFieldText(New_Y)) ; // [Move Button]
		Case Simu  ; // [Simulate Left Click] 
		Val% = MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP ; Left Click
		mouse_event Val, 0, 0, 0, 0
	
	End Select
End Select
Forever

Combine the constants to simulate different clicks, you can simulate a specific mouse wheel move value with MOUSEEVENTF_WHEEL and dwExtraInfo. Also remember that you can move and click simultaneously by using mouse_events dX and dY params.

Look here for reference


Rob(Posted 2004) [#6]
thanks a lot, thats very helpful of you :)


WillKoh(Posted 2004) [#7]
I don't know if you should automate it, users may get scared seeing the mouse move by itself, messing up the desk, knocking out cups of coffee ;)


eBusiness(Posted 2004) [#8]
Hmmm, you could use a cordless mouse as a radio controlled car. I bet Tracer would like the idea.


*(Posted 2004) [#9]
hmm, would be good got a tutorial mode so people could get the idea to click the button that has CLICK ME on it ;). Or a malicous virus that clicks icons on ya desktop :|.