Detecting Input

Started by
3 comments, last by ETFBlade 20 years, 3 months ago
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.
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.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
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.
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]
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.

This topic is closed to new replies.

Advertisement