Trap the Mouse Cursor?

Posted By: WolfCoder

Trap the Mouse Cursor? - 03/21/10 07:53

How do you trap the mouse cursor so that the player doesn't have to worry about their mouse leaving the window when they're trying to look around in an first-person game? I would think this is a feature implemented ever since the engine supported windowed mode because, well, some people want to play my first-person game in windowed mode.

Right now if the player turns around enough, the cursor exits the window which is very bad.

I'm using Acknex Commercial 6.60, but since I just started I can update and it won't break my project if this is in an update.
Posted By: Superku

Re: Trap the Mouse Cursor? - 03/21/10 11:21

It's possible in lite-c with windows.h included:

Originally Posted By: DJBMASTER
#include <acknex.h>
#include <windows.h>

void main()
{
mouse_pointer = 0;
RECT* rect;
GetWindowRect(hWnd,rect);
ClipCursor(rect);
}

Posted By: WolfCoder

Re: Trap the Mouse Cursor? - 03/21/10 19:12

What about C-Script?
Posted By: WolfCoder

Re: Trap the Mouse Cursor? - 03/22/10 08:02

Oh yeah, and your method is flawed. With your method, the player can still accidentally move or close the window as GetWindowRect returns the rectangle including window border and controls. This is not a good method of trapping the mouse.

Thanks for trying to help, but you shouldn't merely parrot back some solution you saw in another thread without thinking if it really does work. I eventually got it to work with the following plugin function:

Code:
/* Captures the mouse */
DLLFUNC void wcmouse_trap()
{
	RECT rect;
	/* Get the rectangle and see if it is different */
	GetClientRect(ev->hWnd,&rect);
	/* Convert to the screen */
	ClientToScreen(ev->hWnd,(LPPOINT)&rect);
	ClientToScreen(ev->hWnd,(LPPOINT)&rect.right);
	/* Clip the rectangle */
	ClipCursor(&rect);
}



This confines the mouse cursor to the client area and not the entire window area so the user cannot accidentally click on the controls or resize the window.

It's just a matter of using mouse_force to look around.

I have created a plugin+C-Script that, when initialized, traps the mouse cursor with an initial pointer appearance of nothing in windowed mode for as long as the window as focus. If you ALT+TAB or otherwise lose the focus, the mouse is released and taken back when the window regains focus.
Posted By: Superku

Idiot - 03/22/10 13:36

Quote:
Oh yeah, and your method is flawed. With your method, the player can still accidentally move or close the window as GetWindowRect returns the rectangle including window border and controls. This is not a good method of trapping the mouse.

Thanks for trying to help, but you shouldn't merely parrot back some solution you saw in another thread without thinking if it really does work.


Oh I'm soooo sorry that I am smart enough to use the search function what you should have done before posting. Now go and celebrate yourself for that plugin.
Posted By: Progger

Re: Idiot - 03/22/10 15:34

try mouse_valid and look what it means in the manual
Posted By: Cowabanga

Re: Idiot - 04/15/10 07:13

Quote:
Hello, members,

Goodbye, spammer.
Posted By: Quad

Re: Idiot - 04/15/10 11:00

@Cowa: wrong tread?
© 2024 lite-C Forums