Keyboard stops time!
I have a single Windows timer in my game - a simple seconds counter...
case WM_TIMER:
secs -= 1;
return 0;
break;
It works fine, except when I hold down a key. If I hold down, say, the "a" key, the timer stops. When I let go the timer starts again.
I handle all my input through a DirectInput keyboard device. There is no WM_KEYDOWN statement in my windowproc function. Why is this happenning!? Might I have to find a different time keeping method than a Windows timer?
No, Canadians DON'T all live in igloos. They live in one BIG igloo!
Hitting a key generates an interrupt which, as the name implies, interrupts the current program (whatever it is) to let the whole system (including your DI libraries) know that a key has been pressed, and which one.
If you read the specifications for timers, you''ll see that the time you specify for the timer is a minimum time. Which means that the timer will not trigger before, but can potentially wait an arbitrarily long time before triggering (Windows is not a real-time operating system).
Your solution ? Use the various timing functions ( clock(), timeGetTime(), QueryPerformanceCounter() ) instead of trying to implement your own.
[Questions (STFW) | GDNet Start Here | GDNet Search | Forum FAQ | Google | Asking Smart Questions ]
[Docs (RTFM) | MSDN | SGI''s STL | OpenGL | File formats]
[C++ Must Haves (RTFS) | MinGW | Boost | Loki | FLTK | SDL ]
Stolen from Magmai Kai Holmlor, who held it from Oluseyi, who was inspired by Kylotan...
If you read the specifications for timers, you''ll see that the time you specify for the timer is a minimum time. Which means that the timer will not trigger before, but can potentially wait an arbitrarily long time before triggering (Windows is not a real-time operating system).
Your solution ? Use the various timing functions ( clock(), timeGetTime(), QueryPerformanceCounter() ) instead of trying to implement your own.
[Questions (STFW) | GDNet Start Here | GDNet Search | Forum FAQ | Google | Asking Smart Questions ]
[Docs (RTFM) | MSDN | SGI''s STL | OpenGL | File formats]
[C++ Must Haves (RTFS) | MinGW | Boost | Loki | FLTK | SDL ]
Stolen from Magmai Kai Holmlor, who held it from Oluseyi, who was inspired by Kylotan...
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
the windows WM_TIMER message is considered a non critical message (like WM_PAINT) and can accumalate with out getting them all so when holding a key yo usend a barage of messges to the window (even if you dont handle them, windows sends them and handles them). WM_TIMER is VERY poor, use timeGetTime() or other timers meant for multimedia apps.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement