Keyboard input using Windows.Form

pin

25-04-2007 02:02:02

I'm using as base the code in Mogre tutorial 5 (Ogre startup sequence).
To get the Windows.Form Input working I inherit OgreStartup from Form. Although I can create a keyboard event handler it doesn't work.

Do I need to do something else other than inheriting from Form to get Windows.Form input working? (I don't want to use MogreFramework)?

Is using Windows.Form keyboard input efficient for an application that is supposed to run fast?

RichTufty

25-04-2007 14:25:43

I personally would use DirectX to grab the input, DirectX.DirectInput

I have some examples if you need it

pin

25-04-2007 15:29:23

I wouldn't mind taking a look =]

[EDIT]
Thanks for suggestion, I have DirectInput working. I got confused by the Loader Lock issue but I have that figured out too.

RichTufty

26-04-2007 19:08:20

Yeah the Loader Lock issue is a pain! Google it if you are having that problem.

I thought i'd quickly post some code here anyway:

First of all include the Direct X in to the program (note: i use DXI to shorten the lengthy API structure)

using Microsoft.DirectX;
using DXI = Microsoft.DirectX.DirectInput;


I set up some class variables so that my different methods can use DX

public DXI.Device
keyboardInputDevice,
mouseInputDevice;

public DXI.KeyboardState
keyState;

public DXI.MouseState
mouseState;


when i initialise my code i set up the input devices

keyboardInputDevice = new DXI.Device(DXI.SystemGuid.Keyboard);
keyboardInputDevice.Acquire();

mouseInputDevice = new DXI.Device(DXI.SystemGuid.Mouse);
mouseInputDevice.Acquire();


then when i want to capture the input values, populate the states

mouseState = mouseInputDevice.CurrentMouseState;
keyState = keyboardInputDevice.GetCurrentKeyboardState();


you can get the x and y values from the mouse state, but to detect key presses use something like this.

if (keyState[DXI.Key.A])
//do something when the A key is pressed

if (keyState[DXI.Key.Z])
// do something when the Z key is pressed


Hope this is useful to anyone?

Tufty

Eldritch

26-04-2007 20:36:25

I found the Axiom stuff from one of the samples to be of particularly good use.