Page 1 of 1

Mouse delta x/y alternative

Posted: Mon Nov 26, 2007 9:21 am
by Mistrel
These functions are similar to PB's MouseDeltaX() and MouseDeltaY() procedures but can be used outside of a 3D window.

Code: Select all

Procedure MouseMoveX()
	Static lastx
	Static callflag
	If Not callflag ; if this procedure has not been called before
		callflag=1
		lastx=DesktopMouseX()
		ProcedureReturn 0
	EndIf
	n=lastx
	lastx=DesktopMouseX()
	ProcedureReturn DesktopMouseX()-n
EndProcedure

Procedure MouseMoveY()
	Static lasty
	Static callflag
	If Not callflag ; if this procedure has not been called before
		callflag=1
		lasty=DesktopMouseY()
		ProcedureReturn 0
	EndIf
	n=lasty
	lasty=DesktopMouseY()
	ProcedureReturn DesktopMouseY()-n
EndProcedure

Repeat
	If GetAsyncKeyState_(#VK_LBUTTON)&32768
		n=MouseMoveX()
		If n<>0
			Debug n
		EndIf
		n=MouseMoveY()
		If n<>0
			Debug n
		EndIf
	EndIf
	Delay(20)
ForEver