How could I keep my mouse pointer inside a canvas or window?
BlitzPlus Forums/BlitzPlus Programming/How could I keep my mouse pointer inside a canvas or window?
| ||
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... 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. |
| ||
Oh, and why doesn't my /code thingy work? Dammit! Sorted. |
| ||
What are the forum codes? |
| ||
Make a "user32.dll" userlib. There is an API call to confine the mouse cursor region: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. |