Mois Capture() cursor lock

dotnot

20-05-2011 09:02:08

Hi guys,

The MOIS mouse Capture() method locks the mouse cursor in the screen center & hides it.
1) Any way to disable it temporarily(for interacting with custom GUI) & still receive mouse events?
2) Show/hide the cursor when required?

GantZ

21-05-2011 18:50:49

Hi,

when you create your inputmanager, use DISCL_NONEXCLUSIVE to avoid locking of the cursor (it also show the windows cursor and share it with other applications)

MOIS.ParamList pl = new MOIS.ParamList();
pl.Insert("w32_mouse", "DISCL_FOREGROUND");
pl.Insert("w32_mouse", "DISCL_NONEXCLUSIVE");
inputManager = MOIS.InputManager.CreateInputSystem(pl);


to show / hide the cursor, you have to use p/invoke on user32.dll


[DllImport("user32.dll")]
public static extern int ShowCursor(bool bShow);


then call ShowCursor() to show / hide the cursor.

dotnot

21-05-2011 20:27:23

Thanks, works as expected. :)

skittle

25-02-2013 17:42:04

GantZ,

Just wanted to say thanks for your solution, you solved a very frustrating problem I was having with my mouse disappearing.

Just in case anybody out there is having the same trouble I was. If you are trying to embed an Ogre3D model in a windows form, you will also need to pass in the external window handle as one of the Paramlist item's.
My solution ended up being,

MOIS.ParamList pl = new MOIS.ParamList();
pl.Insert("w32_mouse", "DISCL_FOREGROUND");
pl.Insert("w32_mouse", "DISCL_NONEXCLUSIVE");
pl.Insert("WINDOW", this.Handle.ToString()); // the handle to my form (window)
inputManager = MOIS.InputManager.CreateInputSystem(pl);

ZetaHunter

20-03-2013 19:06:30

Hey guys, I am having a bit of issue with the mouse still, it is now its always unlocked, and if I am playing in non fulscreen more, it will just go outside the window, is there a function I could call to lock it and unlock? That would be awesome :D

BrainScan

20-03-2013 22:08:12

I use the .NET Cursor class when I'm working in windows forms. It has a bunch of static methods and properties for dealing with the cursor. Such as:

//Hide the cursor, I prefer this to using P/Invoke
Cursor.Hide();
//Show the cursor again
Cursor.Show();

//Keep the cursor within a rectangle on screen. Here gameBox is the picture box I am hosting Mogre in
Cursor.Clip = gameBox.RectangleToScreen(new System.Drawing.Rectangle(viewport.ActualLeft, viewport.ActualTop, viewport.ActualWidth, viewport.ActualHeight));
//Setting it to empty allows the cursor to go anywhere again
Cursor.Clip = System.Drawing.Rectangle.Empty;

ZetaHunter

21-03-2013 12:10:20

the Cursor class did help a bit,
the only problem is I dont want to use a form, when I tried using the functions directly without a form
everything seem to work, except I cant lock the cursor in any other way then centring it to one point on screen, but for that I need to retrive the viewport, but eveytime I try doing so (yes I have my own MainApplication class setup) it still returns Viewport has no link, even though Input Manager gets initialized after Viewport...
I dont know why is this happening, any help will be appriciated :)

ali_lak

22-11-2016 06:28:06

Thank you so much!
it works for me too.

but in my case the code "this.handle.Tostring()" has an exception error and i changed it to this! (in InitializeInput() method)


int windowHandle;
mWindow.GetCustomAttribute("WINDOW", out windowHandle);

MOIS.ParamList pl = new MOIS.ParamList();
pl.Insert("w32_mouse", "DISCL_FOREGROUND");
pl.Insert("w32_mouse", "DISCL_NONEXCLUSIVE");
pl.Insert("WINDOW", windowHandle.ToString());
mInputMgr = MOIS.InputManager.CreateInputSystem(pl);


The problem solved!
Thanks again.