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


Keyboard Buffered Input..

Recommended Posts

I decided to take a step back and rewrite parts of my Engine and I''m focusing on the keyboard. Currently I only support Immediate input which was enough up to a point which is now and I want buffered Input now. My question is ... how would I go about the best way of reading the buffered input? I have a thought of making a timer even that goes off about thirtyish times a second, and each time checking weither a key has been pressed via the GetDeviceData function. I have encapsulated the Keyboard into a class. My assumption that the best way to go about this would be create an internal array and a GetKeys function that would accept an array and copy the information from the internal buffer of events into the array passed then take the array and loop through each key and do the approperate action based on the key pressed. Is this the best way? Hopefully this is clear. Thanks, David.

Share this post

Link to post
Share on other sites
Yeah - I agree Immediate mode''s a problem (especially for menu selection - the arrow scrolling thru the menu is a friggin nightmare).

What I do is hold an array in my class

int m_kbDelay[256]; //delay for each key
char m_kbBuffer[256]; //keyboard buffer to hold keystates

and call ReadInput() (or whatever your function is) every time in your game loop (just like you used to do for immediate mode).

In ReadInput you''d do this

m_pdiKeyboard->GetDeviceState(blah blah blah)

for (int c=0;c<256;c++)
//AND it with the highest bit 0x80
m_kbBuffer[c] &= 0x80;

And this is where you''d incress the m_kbDelay

if (m_kbDelay[c] > 10)
m_kbDelay[c] = 0;

And you would write a function called keypress or something

bool keypress(int key)
if (m_kbBuffer[key] &&
m_kbDelay[key] > 3)
m_kbDelay[key] = 0;
return true;
return false;

Hope I help


Share this post

Link to post
Share on other sites