[SlimDX 11,C#] No RawInput Documentation/tutorial?

Started by
3 comments, last by Starnick 11 years, 11 months ago
I decided to move from directx 9 to 11 and came across SlimDX with C#. Of course most of the things are new and different but somehow I'm managing. Now I wanted to have some kind of an input system for a FPS-like camera and as most people suggested I turned towards SlimDX.RawInput. And...

I'm lost. Completely.

I can't find any sort of material which might explain what all the RegisterDevice and EventHandler functions are and what exactly am I supposed to do. The only thing I could write so far is


class Input
{
public delegate void Input(object obj, SlimDX.RawInput.KeyboardInputEventArgs args);
public void Initialize(Input ip)
{

Device1.RegisterDevice(SlimDX.Multimedia.UsagePage.Generic, SlimDX.Multimedia.UsageId.Keyboard, DeviceFlags.None);
Device1.KeyboardInput += new System.EventHandler<KeyboardInputEventArgs>(ip);

}

};


And I'm not even sure about the function declaration at the top, I just copied that from here http://digg.pp.fi/3d.../InputSystem.cs.

Am I supposed to be looking at the win32 RawInput documentation and just convert it to C# code? Is the SlimDX RawInput similar to the Win32 one or not?

Thanks!
Advertisement
SlimDX is just a wrapper for Directx, giving you access through .net. I've never used it but from what I've read you just pull in the namespace for rawinput, call the register function, setup an event handler and trap the keys / mouse input and process.



SlimDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.Keyboard, DeviceFlags.None);
SlimDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.Mouse, DeviceFlags.None);

SlimDX.RawInput.Device.KeyboardInput += Device_KeyboardInput;
SlimDX.RawInput.Device.MouseInput += Device_MouseInput;

private void Device_MouseInput(object sender, MouseInputEventArgs e)
{
//process input here
}

private void Device_KeyboardInput(object sender, KeyboardInputEventArgs e)
{
process input here
}




http://msdn.microsof...3(v=vs.85).aspx
Thanks for the info!

But my problem is... what exactly to fill out in the input processing function. I've seen the msdn documentation for reading in unbuffered data, they've used WM_INPUT and a function GetRawInputData, which I think I can't use in SlimDX ( I checked the SlimDX RawInput class reference but the function is not there).

Another question: you've made the function to be private, how or what function do I call from outside for updating? Will this keyboard input function be somehow called every time there is a key press or release event?

One more: Does SlimDX contain virtual key enumerations like VK_SPACE or VK_CONTROL to identify the key being pressed?

I'm sorry if all this sounds like spoon feeding, but I'm just not able to understand anything here. :(
I'm not going to be much help in regards to SlimDX. :( The code I posted is suedo code. You could make the functions public or what ever you wanted. You could use your IDE to print out or step through the code to see what the event args are and trap them accordingly. If I remeber correctly, the events will be triggered on keypress and relese.

Keep in mind, you can just as well get keyboard state from the the appropriate P/Invoke calls to [color="#0f72da"]GetKeyboardState and mouse button state from [color="#0f72da"]GetAsyncKeyState. And screen position of the mouse from [color="#0f72da"]GetCursorPos So raw input isn't your only alternative to direct input, or tapping into windows messages.
There isn't a whole lot to the SlimDX RawInput wrapper. If you havent, take a look at the documentation.

The event args that are passed to you uses the System.Windows.Forms.Keys enum. And it doesnt matter if the function is private or not, you only care about responding to events from the input device and won't be calling that function from the message loop. At least when using the SlimDX Wrapper.

How they do it under the hood is exactly that, by responding on WM_INPUT and using GetRawInputData, which is then processed to be consumed by your event handlers. So by doing this work for you, they made it fairly easy to use and the pseudo-code DJTN is pretty much all you need to do to get up and running.

Another thing to keep in mind when comparing this to GetAsyncKeyState is you're going to respond to RawInput as keys are pressed/released, where getting the current keyboardstate is more of a polling process - e.g. in your game loop, when you update your objects, you can poll the input device and respond accordingly. You can of course have a setup where responding to RawInput just keeps track the input state (e.g. keys pressed), which a snapshot of is used everytime your objects are updated. An example: RawInputKeyboardWrapper vs WindowsKeyboardWrapper. Other possible ways would be to buffer the events and handle them in the order they were received.

This topic is closed to new replies.

Advertisement