Original Post
🔒 Locked
DInput keypresses
Advertisement
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!
Hope this helps!
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.
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.
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
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
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement