Skip to main content

History: MOIS

Preview of version: 7

MOIS is the Mogre .NET wrapper for OIS (Object Oriented Input System). It is an object oriented input library and supports many different devices in three basic device categories (keyboards, mice, and joysticks).

Setup

MOIS is included in the Mogre SDK and used by some Mogre-Samples like ExampleApplication.

Set up the library...

  • In your bin/debug directory you need the file MOIS_d.dll.
  • In your bin/release directory you need the file MOIS.dll.
  • In your project add a link to the MOIS.dll library.


Note: In older releases additonally the file OIS.dll was needed, but now it's already embedded in the MOIS.dll file.

Using

In your code...

  • Initialize the MOIS.InputManager and the used devices.
  • Capture your devices and respond to button/key presses.


An example for initializing MOIS can be found in the ExampleApplication from the Mogre-Samples.

Here's a snippet from it:

Copy to clipboard
protected MOIS.InputManager inputManager; protected MOIS.Keyboard inputKeyboard; protected MOIS.Mouse inputMouse; public void CreateInput() { MOIS.ParamList pl = new MOIS.ParamList(); IntPtr windowHnd; window.GetCustomAttribute("WINDOW", out windowHnd); // window is your RenderWindow! pl.Insert("WINDOW", windowHnd.ToString()); inputManager = MOIS.InputManager.CreateInputSystem(pl); // Create all devices (except joystick, as most people have Keyboard/Mouse) using unbuffered input. inputKeyboard = (MOIS.Keyboard)inputManager.CreateInputObject(MOIS.Type.OISKeyboard, false); inputMouse = (MOIS.Mouse)inputManager.CreateInputObject(MOIS.Type.OISMouse, false); }


What I found useful is to adjust the mouse range to the dimensions of the viewport to get the actual mouse position in pixels.

The default mouseState.width and .height values are 50, which are obviously too low to get a smooth mouse movement.

Add this at the end of CreateInput():

Copy to clipboard
MOIS.MouseState_NativePtr mouseState = inputMouse.MouseState; mouseState.width = viewport.ActualWidth; mouseState.height = viewport.ActualHeight;


If you are using Visual Studio the Object Browser is good to see which members are available in MOIS.

Unbuffered mode

In FrameStarted() or FrameEnded() do something like this:

Copy to clipboard
// Capture all key presses since last check. inputKeyboard.Capture(); // Capture all mouse movements and button presses since last check. inputMouse.Capture(); // Get current mouse position (e.g. to inject into GUI). mouseState As MOIS.MouseState_NativePtr = _Mouse.MouseState int screenx = mouseState.X.abs; int screeny = mouseState.Y.abs; if (inputKeyboard.IsKeyDown(MOIS.KeyCode.KC_BACK)) { // ... do something when BACK key is down } if (inputKeyboard.IsKeyDown(MOIS.KeyCode.KC_1)) { // ... do something when 1 key is down } if (mouseState.ButtonDown(MOIS.MouseButtonID.MB_Left)) { // ... do something when left mouse button is pressed }

Buffered mode

Change these line in CreateInput():

Copy to clipboard
// Create all devices (except joystick, as most people have Keyboard/Mouse) using unbuffered input. inputKeyboard = (MOIS.Keyboard)inputManager.CreateInputObject(MOIS.Type.OISKeyboard, false); inputMouse = (MOIS.Mouse)inputManager.CreateInputObject(MOIS.Type.OISMouse, false);

to:

Copy to clipboard
// Create all devices (except joystick, as most people have Keyboard/Mouse) using buffered input. inputKeyboard = (MOIS.Keyboard)inputManager.CreateInputObject(MOIS.Type.OISKeyboard, true); inputMouse = (MOIS.Mouse)inputManager.CreateInputObject(MOIS.Type.OISMouse, true);


Capture input events in FrameStart() or FrameEnded():

Copy to clipboard
// Capture all key presses since last check. inputKeyboard.Capture(); // Capture all mouse movements and button presses since last check. inputMouse.Capture();


Add event handlers to your CreateEventHanlder() method. Mine looks like this:

Copy to clipboard
public void CreateEventHandler() { mRoot.FrameStarted += new FrameListener.FrameStartedHandler(FrameStarted); mRoot.FrameEnded += new FrameListener.FrameEndedHandler(FrameEnded); if (inputKeyboard != null) { LogManager.Singleton.LogMessage("Setting up keyboard listeners"); inputKeyboard.KeyPressed += new MOIS.KeyListener.KeyPressedHandler(KeyPressed); inputKeyboard.KeyReleased += new MOIS.KeyListener.KeyReleasedHandler(KeyReleased); } if (inputMouse != null) { LogManager.Singleton.LogMessage("Setting up mouse listeners"); inputMouse.MousePressed += new MOIS.MouseListener.MousePressedHandler(MousePressed); inputMouse.MouseReleased += new MOIS.MouseListener.MouseReleasedHandler(MouseReleased); inputMouse.MouseMoved += new MOIS.MouseListener.MouseMovedHandler(MouseMotion); } }


Create event handler methods:

Copy to clipboard
public bool MouseMotion(MOIS.MouseEvent e) { // you can use e.state.Y.rel for reltive position, and e.state.Y.abs for absolute return true; } public bool MousePressed(MOIS.MouseEvent e, MOIS.MouseButtonID button) { switch (button) { case MOIS.MouseButtonID.MB_Left: break; } return true; } public bool MouseReleased(MOIS.MouseEvent e, MOIS.MouseButtonID button) { return true; } public bool KeyPressed(MOIS.KeyEvent e) { switch (e.key) { case MOIS.KeyCode.KC_ESCAPE: break; } return true; } public bool KeyReleased(MOIS.KeyEvent e) { switch (e.key) { case MOIS.KeyCode.KC_ESCAPE: break; } return true; }


You can still use the isKeyDown() function to determine the state of your keyboard, just as if you were using immediate/unbuffered mode (more information in this forum post).

See Also

Alternatives

History

Information Version
Mon 10 of Feb, 2014 18:00 GMT-0000 Beauty added and replaced links 18
Tue 24 of Apr, 2012 15:34 GMT-0000 Beauty added link to OISB 17
Tue 24 of Jan, 2012 06:51 GMT-0000 Aralox 16
Tue 24 of Jan, 2012 06:50 GMT-0000 Aralox Added note about paramlist explanation on OIS wiki page 15
Thu 03 of Feb, 2011 22:05 GMT-0000 Beauty added download link for VS2010/.NET4.0 14
Thu 03 of Feb, 2011 16:11 GMT-0000 Beauty mistype correction 13
Thu 03 of Feb, 2011 16:10 GMT-0000 Beauty added tutorial link 12
Wed 18 of Aug, 2010 15:00 GMT-0000 Beauty mistype correction 11
Wed 18 of Aug, 2010 14:59 GMT-0000 Beauty updated repository link 10
Wed 18 of Aug, 2010 14:55 GMT-0000 Beauty added note 9
Wed 18 of Aug, 2010 14:53 GMT-0000 Beauty 8
Wed 18 of Aug, 2010 14:52 GMT-0000 Beauty added subsection "alternatives" 7
Wed 18 of Aug, 2010 14:47 GMT-0000 Beauty updated setup section + added links 6
Thu 11 of Feb, 2010 23:26 GMT-0000 beauty added link to SlimDX (as input alternative) 5
Thu 31 of Dec, 2009 20:06 GMT-0000 jacmoe 4
Thu 31 of Dec, 2009 00:00 GMT-0000 jacmoe 3
Wed 30 of Dec, 2009 11:29 GMT-0000 Beauty See Also: added alternative how to get key inputs 2
Fri 20 of Nov, 2009 00:43 GMT-0000 Beauty added note - OIS.dll not needed 1