• Advertisement

Archived

This topic is now archived and is closed to further replies.

Detecting Input

This topic is 5151 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Heya, Right now I''m trying to figure out the problem of working with Direct Input. I need a way to constantly detect what the user is pressing on the keyboard, if anything and react accordingly. I know there has to be a simpler way then checking a long switch statement for the state of every key every game loop. If anyone has any ideas, they''d be greatly appreciated. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Well, I haven''t gotten far enough in any project yet to actually use Direct Input, although I''ve read a bunch about it. I believe what you''re looking for is buffered data instead of immediate data. If you''re using the GetDeviceState method right now, then check into the GetDeviceData method. Buffered data simply keeps a record of each event that occurs. So you''ll get events such as keydown, keyup, mousemove, and such, I suppose. You''ll still need the big switch statement, but it''ll only run every time something actually happens, not every time through the game loop.

To get even fancier, you can uset the method SetEventNotification. You''d have to set up a second thread that calls WaitForSingleObject, and waits for the Event object that you gave to Direct Input. When the wait is finished, process the event that occured, probably by calling GetDeviceData still, and then do the WaitForSingleObject again, looping the process until the program is done. However, I''m guessing that this method is a bit overkill for what you need.

Share this post


Link to post
Share on other sites
You only need to check for keys that do something. Like if the A key doesn''t do anything, don''t check if it is pressed. Find out how many keys you need. If it is only a few directional keys just use some if statements, especially if this is a relatively basic project.

Share this post


Link to post
Share on other sites
Wrong forum...

As for your question, there is no need to have an extremely large switch statement unless you absolutely NEED to check all the keys. All you need to put in the switch are the keys needed within the game.

EDIT: Too late

[edited by - FaR on January 13, 2004 6:56:39 PM]

Share this post


Link to post
Share on other sites
Well, the problem is that I do in fact need to basically check every single key. There is a long input sequence during the game and I need to check if the key presses are right or not. I''d say the only keys that aren''t being used are insert, prt scr, delete, etc. All letters, numbers and arrows, however, are.

Share this post


Link to post
Share on other sites

  • Advertisement