Sign in to follow this  

Library for keyboard input with timestamps?

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

This topic is 4719 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this