Keyboard with DXInput
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.
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.
#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
#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
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?
I meant setting that particular key to false, not all the rest of the keys being held down.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement