Jump to content
  • Advertisement
Sign in to follow this  
Dobrelius

Library for keyboard input with timestamps?

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

Hi, I am developing an application w/ 3d graphics and physics and the framerate can vary greatly (from 1 - 100 fps) for reasons beyond my immediate control. Therefore I would like to find a portable (Win32, Linux, Mac) way of getting keyboard input with timestamps asyncronously, without resorting to multitheading and/or polling. I know that DirectInput could do it, but unfortunatly neither SDL, Allegro nor any other library I have looked at seem to support this. Any advice?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Dobrelius
Hi,

I am developing an application w/ 3d graphics and physics and the framerate can vary greatly (from 1 - 100 fps) for reasons beyond my immediate control.

Therefore I would like to find a portable (Win32, Linux, Mac) way of getting keyboard input with timestamps asyncronously, without resorting to multitheading and/or polling.

I know that DirectInput could do it, but unfortunatly neither SDL, Allegro nor any other library I have looked at seem to support this.

Any advice?


The only way I can think of accompishing this is along these lines:

Uint8 *keys;
Uint32 timestamps[256];

update loop
{
timestamp = GetTickCount (or platform timer)
keys = SDL_GetKeys(null);
for( int x=0;x<256;x++)
{
/*scan through and see if any key was pressed - if so assign its timestamp to timestamp, if not, -1*/
if( keys[x] )
{
timestamps[x] = timestamps++;
/* this is to make it more realistic, keys cannot be pressed at the same time "in reality" per se because of the way windows works.*/
}

... process input ...

clearalltimestamps this frame
}

of course if you wanted to use a buffered input approach that DI uses, you could have some

Uint8 *keys[buffer levels];

Just an idea.

- Drew

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!