Jump to content
  • Advertisement

Archived

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

Houdini

DInput keypresses

This topic is 6700 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

Is there an easier way to detect keypresses in between frames using direct input than to use a for loop and manually check each key? It seems like a huge waste of processing power to have a 0 to 100 for loop just to check for keypresses in between every single frame...

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
A loop ?
I can hardly imagine why you should use a 1..100 loop to check your keys...

Either you''re using immediate data mode and are calling GetDeviceState(), in which case you''ll just get an array containing the status of all keys, then you''ll just check the keys needed by you game, ex.

 unsigned char keys[256];
 int key_left = DIK_LEFT;
 int key_right = DIK_RIGHT;
 
 DIKeyboard->GetDeviceState(keys, sizeof(keys));
 if(keys[key_left])
   some_x -= 1;
 if(keys[key_right])
   some_x += 1;

...or you''re using buffered mode, where you''ve got something like this:

 DIDEVICEOBJECTDATA DIDObjectData[128];
 DWORD numevents;
 unsigned char keys[256];
 int count;
 
 DIKeyboard->GetDeviceData(sizeof(DIDObjectData), DIDObjectData, &numevents, 0);
 for(count = 0; count < numevents; count++)
   keys[DIDObjectData[count].dwOfs] = DIDObjectData[count].dwData & 128;

In both cases, a loop makes no sense to me. Perhaps you could explain in some more detail or even post part of your code ?

-Markus-

Share this post


Link to post
Share on other sites
Well, I had the same problem just a few weeks ago. As far as I know, there''s no way around it. I''ve had to check for each key one by one as well (in a loop of course). I think the whole point of DirectInput with a keyboard device is to turn the keyboard into a HUGE gamepad. Just check for the keys you want, and do what you need to do with the input.

Hope this helps!

Share this post


Link to post
Share on other sites
I''m with Markus. I personally use buffered input for the keyboard. You don''t do ANY processing of keyboard input (beyond calling GetDeviceData) unless there has been some. If you are worried about states, keep track of that internally -- (dumb example):

bool forwardKeyPressed;

void onForwardKeyPressed()
{
forwardKeyPressed = true;
}

void onForwardKeyReleased()
{
forwardKeyPressed = false;
}

Then you have a very easy time during the app loop:

if ( forwardKeyPressed )
moveForward();

Yes, this is very dumb and simplistic, but that''s kinda the point.

Share this post


Link to post
Share on other sites
i came up with a simplistic system to handle keyboard inputs
i setup buffered input mode, and then save a pointer to a function with parameters of a DWORD state, a DWORD which_key, and a void* passed to the function by the caller
this is then used as a callback function, where my little encapsulating class has an update function called which is passed the void pointer
the callback is then called for each keypress in order since the last update
very simple, but a very easy and intuitive system that resembles WndProc

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!