Keyboard and Mouse Input

Started by
4 comments, last by codeToad 11 years, 11 months ago
So I need to experiment with mouse and keyboard input and i'm using DirectX to render sprites in this pathfinding app that i'm building. I checked out the latest DirectX SDK documentation and they say this:

"The use of DirectInput for keyboard and mouse input is not recommended, Windows messages should be used instead"

It links off to a doc on how to use Windows messages. Specifically it describes WM_MOUSEMOVE and this links to the msdn documentation.

I also read about the same stuff here:

http://www.toymaker....html/input.html

tbh, the raw input stuff looks more complicated than just straight keyboard input and mouse input. Am I right in thinking that Keyboard Input done with Windows Messages in this way is based off the Windows API. Because I don't think it is part of DirectX. XInput and DirectInput are part of DirectX.

I suppose the reason for my post is to ask if Windows messages is the usual way of tackling keyboard and mouseinput? And also, what is the best way of getting this information over to the rendering part of my code base. I have already started using Windows messages to pass x, y screen co-ordinates of the mouse over to some rendering code like this:

http://ideone.com/4Ho4F

But I imagine that with all of the input I need to process for my project, the [color=#000066]

[background=rgb(240, 240, 240)]WndProc() [/background] function is going to become quite crowded.

--
Wisey

Advertisement
The Raw Input API is more simple then you think. Simply read the documentation for 10 minutes and it makes complete sense, and is generally considered the best method for input handling. More powerful and more robust
I just switched to Raw Input from DirectInput, and I felt the same way as you at first. After getting it working (didn't take long), the code seems a lot simpler than the DirectInput method.
The mouse and keyboard input you get from the standard windows messages (WM_MOUSEMOVE, WM_KEYDOWN, WM_CHAR, etc.) are designed for GUI apps. So for instance you get the position of actual Windows mouse cursor, and the keys will use the designated repeat rate and will go through Unicode translation. Raw input is for getting raw unfiltered data from the hardware. So you get actual mouse movement data, and not the filtered cursor movement. This makes it good for an FPS where you want to take advantage of a high DPI mouse and have precision aiming, but it doesn't make sense if you have a cursor for selecting menu items. So you should choose which API you use based on your needs.

DirectInput on XP and higher is just a wrapper around raw input, so there's no difference in the functionality.

DirectInput on XP and higher is just a wrapper around raw input, so there's no difference in the functionality.


The one crucial difference being that DI will run your input in a separate thread, whereas with RI you have to set this part up yourself. Depending on your needs, either may be preferable to the other.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

I went through the same raw input tutorial on toymaker. I agree that it seemed complex at first, but after a while you'll realize it's not that bad.

As for your WndProc becoming too crowded, I'd recommend you make methods like OnMouseMove(x, y) and OnKeyDown(keyCode), and just call those methods from WndProc.

This topic is closed to new replies.

Advertisement