Jump to content

  • Log In with Google      Sign In   
  • Create Account


Input for a windows game


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 SoulSharer   Members   -  Reputation: 268

Like
0Likes
Like

Posted 18 March 2012 - 09:41 AM

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!

Sponsor:

#2 rip-off   Moderators   -  Reputation: 6864

Like
2Likes
Like

Posted 18 March 2012 - 11:34 AM

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.

Caveat: I am not a Win32 programmer.

#3 Slig Commando   Members   -  Reputation: 324

Like
0Likes
Like

Posted 18 March 2012 - 07:52 PM

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.

#4 ApochPiQ   Moderators   -  Reputation: 12344

Like
3Likes
Like

Posted 18 March 2012 - 09:55 PM

Required reading.

#5 SoulSharer   Members   -  Reputation: 268

Like
0Likes
Like

Posted 19 March 2012 - 03:07 AM

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. =(

#6 ApochPiQ   Moderators   -  Reputation: 12344

Like
0Likes
Like

Posted 19 March 2012 - 01:25 PM

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.

#7 Krohm   Crossbones+   -  Reputation: 2733

Like
0Likes
Like

Posted 19 March 2012 - 11:47 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS