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 / Restricting mouse for windowed mode

Author
Message
Dixan Anips
22
Years of Service
User Offline
Joined: 9th Nov 2003
Location:
Posted: 1st Dec 2003 14:42
I've done a forum search but came up with nothing on this. Can anyone help with the following?

Q. How can I restrict the mouse pointer to be within the confines of my window when running in windowed mode?

TIA
Andy
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 1st Dec 2003 15:42
You could do it using the POSITION MOUSE command, but that's not perfect ...

The alternative is to dip into the user32 dll for ClipCursor/GetClipCursor functions.

I don't have time to do an example now, but if no-ones done it for you by the time I get back this afternoon, I'll put one together for you
Andy Igoe
23
Years of Service
User Offline
Joined: 6th Oct 2002
Location: United Kingdom
Posted: 1st Dec 2003 16:53
Using the position mouse command would not be very smooth because the mouse would not be repositioned quickly enough and would jitter.

I would probably solve this by hiding the mouse and placing my own sprite where the mouse co-ordinates are, combining that with the position mouse command would negate the jitter of the mouse leaving the window.

You could also use the Windows dll's as IanM suggested, I wonder what would happen if the program later crashes?


God created the world in 7 days, but we're still waiting for the patch.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 1st Dec 2003 17:51
Your mouse would still be restricted to that area. Some windows commands affect things system-wide - this is one of them.

Your suggestion is probably the best way to go.
Dixan Anips
22
Years of Service
User Offline
Joined: 9th Nov 2003
Location:
Posted: 2nd Dec 2003 14:41
Guys, thanks so far but I'm still not sure of the "sprite" thing.

As it stands I've hidden the mouse (hide mouse) but mouse input is still used/required. If the mouse pointer moves outside of the window it re-appears (as it should because Windows is just doing it's job) but as soon as a mouse button click is required by the game Windows takes it as a click on the desktop or other window thereby taking the focus from the game window. I don't understand how placing a sprite over the mouse would stop this effect. Can you enlighten me?

The result I'm trying to get is the same as most commercial games i.e. Jedi Knight/Jedi Academy whereby the mouse pointer is physically restricted to the window and the only way you can switch to a different window/desktop is via the keyboard shortcuts (alt-tab being one of them).

TIA
Andy
Dixan Anips
22
Years of Service
User Offline
Joined: 9th Nov 2003
Location:
Posted: 2nd Dec 2003 14:44
Hmmm... just re-read everything and the "combining that with the position mouse command" explains how to stop the mouse from moving outside of the window.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd Dec 2003 14:51
All you need to do in that case is reposition the mouse to the centre of your window every sync. Then you can continue to use the mousemovex/mousemovey functions to get positional adjustments.
Dixan Anips
22
Years of Service
User Offline
Joined: 9th Nov 2003
Location:
Posted: 2nd Dec 2003 14:52
Right I've just tried with

hide mouse
do
position mouse (screen width() /2), (screen height() /2)
...
loop

and that works fine.

Still not sure about the "sprite" bit but doesn't look like it's needed. Unless you can tell me otherwise, Andy, Ian?

Cheers for the pointers anyway.

Andy
Dixan Anips
22
Years of Service
User Offline
Joined: 9th Nov 2003
Location:
Posted: 2nd Dec 2003 14:53
Thanks Ian, you just beat my post by seconds!
time_hawk
22
Years of Service
User Offline
Joined: 3rd Dec 2003
Location: England
Posted: 3rd Dec 2003 17:16
the sprite essentially replaces the normal windows cursor within your program. it can also be setup so that it doesnt leave the window of your program. simply add a series of if commands after the mousemove checks. eg. mymousex = mymousex + mouse move x() , if mymousex < 0 then mymousex=1. the right hand side will depend on the screen size chosen by you.

good luck.

Login to post a reply

Server time is: 2026-07-26 20:14:42
Your offset time is: 2026-07-26 20:14:42