How could I keep my mouse pointer inside a canvas or window?

Archives Forums/BlitzPlus Programming/How could I keep my mouse pointer inside a canvas or window?

SuperDan(Posted 2003) [#1]
I am trying to make sure that the user cannot move the mouse outside the canvas. I have managed to do it using lots of if endif's but this is very untidy, is there an easier way.
Here is my way...

format_code('If MouseX(Desktop()) < (ClientWidth(Desktop()))/2-374
MoveMouse (ClientWidth(Desktop()))/2-374,MouseY(Desktop())
FlipCanvas(currentcanvas)
EndIf')

...this just checks the left most X position.
If the mouse is outside the edge of my canvas it is put back inside. The only problem is that the pointer can be drawn outside if you move the mouse fast enough.


SuperDan(Posted 2003) [#2]
Oh, and why doesn't my /code thingy work? Dammit!

Sorted.


EOF(Posted 2003) [#3]
faq_link('2')


cyberseth(Posted 2003) [#4]
Make a "user32.dll" userlib. There is an API call to confine the mouse cursor region:

format_code('ClipCursor% ( Rect* )

Type Rect
Field left
Field right
Field top
Field bottom
End Type')

But if you do this, MAKE SURE that you set the cursor's clip region back to the screen size again, so that other appilcations can use the mouse. And when you close your Blitz app, the cursor's clip region does not automatically get reset. So beware.