# Library for keyboard input with timestamps?

This topic is 4795 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
Is this a multiplayer game? If not, I don't quite understand why polling will not suffice.

Ryan

##### Share on other sites
Quote:
 Original post by DobreliusHi,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