Skip to main content
History: MOIS
View published page
Source of version: 18
(current)
MOIS is the ((MOGRE|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). {maketoc} !!Setup MOIS is included in the ((MOGRE|Mogre)) SDK and used by some Mogre-Samples like ExampleApplication. If you need MOIS for VS2010/.NET 4.0, you can download the binaries [https://bitbucket.org/mogre/mogreaddons/downloads/MOIS_VS2010_NET4.zip|here]. 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: {CODE(wrap="1", colors="c#")} 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); }{CODE} Note: For more info on the ParamList, see the [http://www.ogre3d.org/tikiwiki/tiki-index.php?page_ref_id=959|OIS Wiki page] 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()'': {CODE(wrap="1", colors="c#")} MOIS.MouseState_NativePtr mouseState = inputMouse.MouseState; mouseState.width = viewport.ActualWidth; mouseState.height = viewport.ActualHeight;{CODE} 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: {CODE(wrap="1", colors="c#")} // 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 }{CODE} !!!Buffered mode Change these line in ''CreateInput()'': {CODE(wrap="1", colors="c#")} // 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);{CODE} to: {CODE(wrap="1", colors="c#")} // 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);{CODE} Capture input events in ''FrameStart()'' or ''FrameEnded()'': {CODE(wrap="1", colors="c#")} // Capture all key presses since last check. inputKeyboard.Capture(); // Capture all mouse movements and button presses since last check. inputMouse.Capture();{CODE} Add event handlers to your ''CreateEventHanlder()'' method. Mine looks like this: {CODE(wrap="1", colors="c#")} 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); } }{CODE} Create event handler methods: {CODE(wrap="1", colors="c#")} 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; }{CODE} 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 [http://www.ogre3d.org/phpBB2/viewtopic.php?p=122212#122212|forum post]). !!See Also * ((OIS)) * ((Using OIS)) * ((Mogre New Basic Tutorial 4)) - Input using MOIS (see section ''Processing Input'') * ((MadMarx Tutorial 10)) - Input Using OIS (C++) * [https://bitbucket.org/mogre/mogreaddons/src/tip/MOIS/|MOIS source code] * [http://www.ogre3d.org/addonforums/viewtopic.php?f=8&t=7697|MOGRE, MOIS and embeded OGRE Window] - more example code for MOIS * [http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=8495|German keyboard layout] (remapped keys) * [http://geeksden.sourceforge.net/OISAPI.zip|OIS API created with doxygen] * [http://www.wreckedgames.com/forum/index.php?board=6.0|OIS User Forum] * [http://www.ogre3d.org/forums/viewtopic.php?f=1&t=60635|OISB] - input library, which wraps OIS and provides means to make action binding/mapping ** %beginsmall%OISB is currently only available in C++. If somebody port it to C# (or managed C++), please add a link here.%endsmall% !!Alternatives * [http://www.ogre3d.org/forums/viewtopic.php?p=322494#p322494|Input handling by WinAPI] as alternative to OIS (a little bit more efficient; needed for multiple mice or keyboards) * [http://www.codeplex.com/SharpInputSystem|SharpInputSystem] - an other input alternative (alpha status, latest code in SVN) * [http://slimdx.org|SlimDX] - an open source framework for easy use of DirectX by C# (e.g. inputs from keyboard, mouse, gamepad - see tutorials in the SlimDX SDK) You just need the file ''SlimDX.dll'' and the newest DirectX version. * [http://blogs.msdn.com/michkap/archive/2006/03/23/558674.aspx|Getting all you can out of a keyboard layout] - an alternative how to get key inputs ** [http://www.ogre3d.org/addonforums/viewtopic.php?p=51195#p51195|modified code snippet for Mogre] ** [http://www.ogre3d.org/addonforums/viewtopic.php?p=67154#p67154|one more note]
Search by Tags
Search Wiki by Freetags
Latest Changes
Projects using OGRE
Building Your Projects With CMake
Compiled API Reference
Overlay Editor
Introduction - JaJDoo Shader Guide - Basics
RT Shader System
RapidXML Dotscene Loader
One Function Ogre
One Function Ogre
...more
Search
Find
Online Users
157 online users
OGRE Wiki
Support and community documentation for Ogre3D
Ogre Forums
ogre3d.org
Log in
Username
Password
CapsLock is on.
Remember me (for 1 year)
Log in