Input for a windows game

Started by
5 comments, last by Krohm 12 years, 1 month ago
Hello there.

I'm currently trying to figure out how to properly use Raw Input and I'm just a bit confused. Well, previously I worked with DirectInput, but its deprecated and Microsoft advises not to use this one for mouse and keyboard. So thats why I'm switching to Raw Input.

I want to implement the same approach used in XNA

KeyboardState keyState = Keyboard.GetState();
if (keyState.IsKeyDown(Keys.Q))
{
//do something on keydown
}

MouseState mouseState = Mouse.GetState();
if (mouseState.LeftButton == ButtonState.Pressed)
{
//do something on left mouse button pressed
//you can get coordinates of the mouse as mouseState.X and mouseState.Y
}
Is there any way to implement the same concept with Raw Input? And how would I implement that?

Link, search suggestion or a book name will be more than enough.
I appreciate your help. Thanks!
Advertisement
Raw Input is not necessary for this, unless perhaps if you need high resolution mouse input. You can use standard Windows input to implement an XNA-style interface.

For the former, use GetKeyboardState. For the latter, you can use GetAsyncKeyState (yes - it works with mouse buttons) and GetCursorPos() and ScreenToClient() to get the mouse position.

Alternatively just handle regular input events in your message loop.

[size=2]Caveat: I am not a Win32 programmer.
If you are creating an input system for a game, DO NOT use windows messages to handle such things. It is sloppy, and terrible to maintain, plus it is limiting in certain aspects of mouse control. Create a wrapper class that uses RawInput for best results. If you are having trouble figuring it out, just keep it up and you will eventually figure it out. I am not at my work computer right now, other wise I would post some code and explanations, but RawInput is pretty simple to use once you figure it out, plus it is much more versatile and powerful than standard windows messages.
Required reading.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Thanks for the help guys.

I have very last question do I need to make a class that will be filled from WM_INPUT event (each time it's called)? Or do I need to get input in game loop itself somehow (maybe with some function) and feed it into input class I'll make?
And won't feeding from WM_INPUT make a glitch in the whole input system? I mean maybe there are delays between event calls.


Required reading.


Good article, its very useful, yet you are using WM_KEYUP / WM_KEYDOWN in the source code. =(
The article is more about the high level side of what you're doing. Hooking in WM_INPUT should be pretty straightforward if you copy the structure provided in the code.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

As a side note, I am not well aware of any benefits of using WM_INPUT for keyboard handling. I don't recall having any issues with WM_KEY messages.
I'd appreciate more elaborations on that.

Previously "Krohm"

This topic is closed to new replies.

Advertisement