Restrict mouse movement

Find quick help here to get you started with Hollywood
Post Reply
ocean77
Posts: 111
Joined: Mon Jan 28, 2019 8:34 pm

Restrict mouse movement

Post by ocean77 »

Is there a simple and fast command or method for restricting mouse movement to a specific area of the display while a certain condition is true?
amyren
Posts: 352
Joined: Thu May 02, 2019 11:53 am

Re: Restrict mouse movement

Post by amyren »

Perhaps this does not qualify for the "simple and fast" criterias, but it will limit the mouse movements

Code: Select all

@DISPLAY {Width = 640, Height = 480}

Function p_keyhandler(msg)
	Switch(msg.action)
	Case "CloseWindow":
		End
	Case "OnRawKeyDown":
		If msg.key = "X" Then p_poscheck
	EndSwitch
EndFunction

Function p_poscheck()
	xpos = MouseX()
	ypos = MouseY()
	If xpos > 590 
		xpos = 590
		outsidelimit = True
	EndIf
	If xpos < 50 
		xpos = 50
		outsidelimit = True
	EndIf
	If ypos > 430
		ypos = 430
		outsidelimit = True
	EndIf
	If ypos < 50
		ypos = 50
		outsidelimit = True
	EndIf
	If outsidelimit
		MovePointer(xpos, ypos)
		outsidelimit = False
	EndIf
EndFunction

InstallEventHandler({OnRawKeyDown = p_keyhandler, CloseWindow = p_keyhandler})

Repeat
	WaitEvent()
Forever
ocean77
Posts: 111
Joined: Mon Jan 28, 2019 8:34 pm

Re: Restrict mouse movement

Post by ocean77 »

amyren wrote: Wed Jul 20, 2022 8:16 pm Perhaps this does not qualify for the "simple and fast" criterias, but it will limit the mouse movements
Thanks! Will try and see. :D
Post Reply