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?
| 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
...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!|
| faq_link('2') |
| Make a "user32.dll" userlib. There is an API call to confine the mouse cursor region:|
format_code('ClipCursor% ( Rect* )
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.