Page 1 of 1
Limit mouse pos on screen
Posted: Thu Jan 07, 2010 5:05 am
by donSHAYA
Hi all
How do you limit the area (on the opened screen) that the mouse can drive on . Like if I don't want the mouse to be able to drive on the area (x1 = 5, y1 = 5, x2 = 150, y2 = 150).
Or if I only want the mouse to be able to drive on the area (x1 = 50, y1 = 50, x2 = 600, y2 = 600).
Thank You
Re: Limit mouse pos on screen
Posted: Thu Jan 07, 2010 10:33 am
by jamirokwai
donSHAYA wrote:Hi all
How do you limit the area (on the opened screen) that the mouse can drive on . Like if I don't want the mouse to be able to drive on the area (x1 = 5, y1 = 5, x2 = 150, y2 = 150).
Or if I only want the mouse to be able to drive on the area (x1 = 50, y1 = 50, x2 = 600, y2 = 600).
Thank You
Hi,
if you draw a Sprite at the mouse position, you could say (just a dirty hack without having PB installed here...)
Code: Select all
x = MouseX()
y = MouseY()
If x < 50 : x = 50 : endif
if x > 600 : x = 600 : endif
If y < 50 : y = 50 : endif
if y > 600 : y = 600 : endif
DrawTransparentSprite(0,x,y)
This is how I did it in Borland Pascal for Dos

Re: Limit mouse pos on screen
Posted: Thu Jan 07, 2010 12:00 pm
by Kaeru Gaman
almost
... relocating would be good
Code: Select all
x = MouseX()
y = MouseY()
If x < 50 : x = 50 : endif
if x > 600 : x = 600 : endif
If y < 50 : y = 50 : endif
if y > 600 : y = 600 : endif
MouseLocate(x,y)
DisplayTransparentSprite(0,x,y)
otherwise the mouse pointer could show a jumpy behaviour.
Re: Limit mouse pos on screen
Posted: Thu Jan 07, 2010 12:21 pm
by einander
This is for trap Mouse inside a window region.
May be you can adapt it for screen.
Code: Select all
Procedure MouseTrap(X,Y,Wi,He)
GetWindowInfo_(WindowID(EventWindow()),@P.WindowInfo)
WX=P\RcClient\Left
Wy=P\RcClient\Top
SetRect_(R.RECT,WX+X,Wy+Y,WX+X+Wi,Wy+Y+He)
ClipCursor_(@R)
EndProcedure
OpenWindow(0, 0, 0, 600, 600, "Mouse Trap - <ESC> to close window", 1)
Btn1=ButtonGadget(-1,200,100,200,200,"QUIT")
Repeat
Ev = WaitWindowEvent()
If GetAsyncKeyState_(27)&$8000 : End : EndIf
MouseTrap(200,100,200,200)
Until Ev = #PB_Event_Gadget And EventGadget()=Btn1
End
Re: Limit mouse pos on screen
Posted: Thu Jan 07, 2010 6:12 pm
by donSHAYA
Thanks for all replies.
I used Kaeru Gaman's example because it worked while OpenScreen. The mousetrap didn't work while OpenScreen.
But thank you for every reply. very helpful