Archived

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

Keyboard with DXInput

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

I define KEY_DOWN to detect when keyboard is pressed like tihs: #define KEY_DOWN(key) (KeyBuffer[key] & 0x80) However I think I require define KEY_UP as well. I got a problem which processing only KEY_DOWN cannot be solved: ProcessKeyboard() { if (KEY_DOWN(DIK_L)) g_light = !g_light; } SetState() { if (g_light) glEnable(GL_LIGHTING); else glDisable(GL_LIGHTING); } When pressed "L", the result is not regularly right, it would "twinkle" between states. How could I solve the problem with DXInput? If I''d like to define KEY_UP, then what should I AND? #define KEY_UP(key) (KeyBuffer[key] & ?) Thanks.

Share this post


Link to post
Share on other sites
This is because you''re game is checking the state of the keyboard too quickly. After seeing if the ''L'' key has been pressed, set it to false. This will overcome your problem, only the user wont be able to hold down the ''L'' key to get it to change to true & false automatically.

Share this post


Link to post
Share on other sites
#define KEY_DOWN(key) (KeyBuffer[key] & 0x80)
#define KEY_UP(key) !KEY_DOWN(key)

or

#define KEY_UP(key) !(KeyBuffer[key] & 0x80)


it is not a good idea to set it to false, what are you gonna do when the player hits "forward" key. Does he/she need to press it again and again to walk forward?

Oztan

www.geocities.com/proje_x

Share this post


Link to post
Share on other sites

Hey, great thanks for that.
Now I define KEY_UP, and checking keyboard like this:

if (KEY_DOWN(DIK_L) && !lp)
{
lp = true;
g_light = !g_light;
}
if (KEY_UP(DIK_L))
lp = false;

It function well, though, I have to maintain one additional variable per state changes.
Hmm... checking KEY_UP is a good way to go,
but I''m wondering if there''re some other approach to cope with the problem more efficiently?

Share this post


Link to post
Share on other sites