Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Bind mouse to window?

Author
Message
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 15th Dec 2012 17:24
Is there any way to bind the mouse to the window, so it can't leave the boundaries of it?

Thanks,

TheComet

Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 15th Dec 2012 17:44
Position Mouse Clamp( MouseX(), 0, Screen Width() ), Clamp( MouseY(), Screen Height() ) should work I think. You may need the desktop mouse position, I can't remember.

Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 15th Dec 2012 17:46
not in an official way.
but u can check if your mouse is out of your window by checking the X/Y position of the mouse by desktop by using user32.dll dll..

lets say you can get a mouse position of the desktop:


now, all you need to do is in your loop make a check if its out your window and position mouse back to the frame

Advanced Updater for your games!
Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 15th Dec 2012 17:56
here is a quick example i made for you..



Advanced Updater for your games!
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 15th Dec 2012 21:24 Edited at: 15th Dec 2012 21:31
I came up with this solution, using the User32 API function; ClipCursor.



Typed this in on a iPhone, so I hope there are no errors.
mistsnake
16
Years of Service
User Offline
Joined: 24th Apr 2010
Location: Inside the matrix
Posted: 27th Dec 2012 15:32
stopping mouse from leaving window... are you trying to bug whoever uses what you writing - it breaks the whole principle of multitasking, to move between multiple tasks
well its your choice but i can tell you the very few apps i've used that have done that bugged me to hell, be sure to at least provide a easy switch off so mouse can leave you app without closing it down
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 27th Dec 2012 16:23
Quote: "well its your choice but i can tell you the very few apps i've used that have done that bugged me to hell, be sure to at least provide a easy switch off so mouse can leave you app without closing it down"


When playing my RTS game on dual monitors, the mouse will leave the game screen and move over onto the other monitor. Since camera navigation is controlled by moving your mouse to the edge of the screen, it can get quite annoying when you overshoot the app and the mouse leaves the window. That's the reason for it.

I still haven't been able to try this, Christmas and all. I'll let you know as soon as I test it though!

TheComet

Official PonyCraft blog : http://blankflankstudios.blogspot.ch/
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 29th Dec 2012 17:19 Edited at: 29th Dec 2012 17:24
@ WickedX

Your solution is the most elegant, thanks! There's only one problem now. If I alt-tab away from the game and back, it doesn't remain clipped anymore. Is there a way to detect if the user has unfocused the window?

[EDIT] screen invalid()

TheComet

Official PonyCraft blog : http://blankflankstudios.blogspot.ch/
GreenDixy
17
Years of Service
User Offline
Joined: 24th Jul 2008
Location: Toronto
Posted: 29th Dec 2012 18:34
Sent you A email with one of my codes i use for my mouse setup.

"Tittle: Mouse Lock"

======================================
My software never has bugs. It just develops random features.
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 29th Dec 2012 22:29 Edited at: 29th Dec 2012 22:34
On my Windows XP system the cursor remains clipped after alt-tabbing. I put this code after the sync command, it will free the cursor when you alt-tab and clip it again when the window regains focus.

Login to post a reply

Server time is: 2026-07-07 18:44:38
Your offset time is: 2026-07-07 18:44:38