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
Limit mouse pos on screen
-
jamirokwai
- Enthusiast

- Posts: 798
- Joined: Tue May 20, 2008 2:12 am
- Location: Cologne, Germany
- Contact:
Re: Limit mouse pos on screen
Hi,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
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)
Regards,
JamiroKwai
JamiroKwai
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: Limit mouse pos on screen
almost
... relocating would be good
otherwise the mouse pointer could show a jumpy behaviour.
... 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)oh... and have a nice day.
Re: Limit mouse pos on screen
This is for trap Mouse inside a window region.
May be you can adapt it for screen.
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
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
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
