mouse moving on desktop...

BlitzMax Forums/BlitzMax Programming/mouse moving on desktop...

Hello!

May anybody tell me if it is possible to move the mouse on the desktop with a code?! If yes, how to do so?

You can use SendInput or mouse_event. I can't remember why, but I'm pretty sure I read that mouse_event ( much like keybd_event ) is not recommended any more. But hey, try both and see how they go.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputfunctions/sendinput.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/mouseinput/mouseinputreference/mouseinputfunctions/mouse_event.asp

Try this, it shouldn't be hard to convert it to BMax code, I would do it, but I'm a little busy right now.

Mouse userlib

I tried to update the SetCurorPos and mouse_event to the user32.dll in /pub.mod/win32.mod and recompiled the modules. But I still get the msg, that he don't know this two functions. öÔ

May somebody show me how it will work please?

Here:


' // Blitz Max Code
' //=============================
' // Mouse API Function Example by Eikon
' // Converted to Blitz Max by Plash
' // Note: This only works on WIN32
' //=============================

Extern "win32"
	Function SetCursorPos%(x%, y%)
	Function mouse_event%(dwFlags%, dx%, dy%, cButtons%, dwExtraInfo%)
End Extern

Desk_W = ClientWidth(Desktop())
Desk_H = ClientHeight(Desktop())

' // [GUI]
Global Parent:TGadget = CreateWindow("Automate Mouse", (Desk_W / 2) - 75, (Desk_H / 2) - 61, 150, 122, 0, 1)
Global New_X:TGadget  = CreateTextField(5, 5, 64, 18, Parent, 0)
Global New_Y:TGadget  = CreateTextField(75, 5, 64, 18, Parent, 0)
Global Move:TGadget   = CreateButton ("Move Mouse", 5, 26, 134, 18, Parent, 1)
Global Simu:TGadget   = CreateButton ("Simulate Click", 5, 48, 134, 18, Parent, 1)
Global SimuMove:TGadget   = CreateButton ("Move&Simu Click", 5, 70, 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


Const Val% = MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP ' Left Click

' // [Main]
Repeat
	
Select WaitEvent()
    Case EVENT_WINDOWCLOSE
		End
		
    Case EVENT_GADGETACTION ' // [Gadget Event]
	    Select EventSource()
	        Case Move ' // [Move Button]
	        	SetCursorPos Int(TextFieldText(New_X)), Int(TextFieldText(New_Y))
	      
	        Case Simu  ' // [Simulate Left Click] 
	        	mouse_event Val%, 0, 0, 0, 0
				
			Case SimuMove
				SetCursorPos Int(TextFieldText(New_X)), Int(TextFieldText(New_Y))
				mouse_event Val%, 0, 0, 0, 0
				
	    End Select
End Select
Forever