Sign in to follow this  
Manpreet Singh

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

Recommended Posts

Manpreet Singh    271
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
[code]

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);

}

};
[/code]

And I'm not even sure about the function declaration at the top, I just copied that from here [url="http://digg.pp.fi/3d/src/Main/EntitySystem/SubSystems/InputSystem.cs"]http://digg.pp.fi/3d.../InputSystem.cs[/url].

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!

Share this post


Link to post
Share on other sites
DJTN    207
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.

[CODE]

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
}

[/CODE]


[url="http://msdn.microsoft.com/en-us/library/windows/desktop/ms645543(v=vs.85).aspx"]http://msdn.microsof...3(v=vs.85).aspx[/url] Edited by DJTN

Share this post


Link to post
Share on other sites
Manpreet Singh    271
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. :(

Share this post


Link to post
Share on other sites
DJTN    207
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 [url="http://pinvoke.net/default.aspx/user32/GetKeyboardState.html"][color="#0f72da"]GetKeyboardState[/color][/url] and mouse button state from [url="http://pinvoke.net/default.aspx/user32/GetAsyncKeyState.html"][color="#0f72da"]GetAsyncKeyState[/color][/url]. And screen position of the mouse from [url="http://pinvoke.net/default.aspx/user32/GetCursorPos.html"][color="#0f72da"]GetCursorPos[/color][/url] So raw input isn't your only alternative to direct input, or tapping into windows messages.

Share this post


Link to post
Share on other sites
Starnick    1892
There isn't a whole lot to the SlimDX RawInput wrapper. If you havent, take a look at the [url="http://slimdx.org/docs/#N_SlimDX_RawInput"]documentation[/url].

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 [url="http://code.google.com/p/slimdx/source/browse/trunk/source/rawinput/DeviceRI.cpp"]under the hood[/url] 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 [i]GetAsyncKeyState[/i] 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: [url="http://code.google.com/p/tesla-engine/source/browse/trunk/Source/Tesla.Windows/Input/RawInputKeyboardWrapper.cs"]RawInputKeyboardWrapper [/url]vs [url="http://code.google.com/p/tesla-engine/source/browse/trunk/Source/Tesla.Windows/Input/WindowsKeyboardWrapper.cs"]WindowsKeyboardWrapper[/url]. Other possible ways would be to buffer the events and handle them in the order they were received.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this