[gameprogrammer] Re: Key Repeat problem
- From: David Olofson <david@xxxxxxxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Fri, 20 Jan 2006 09:19:25 +0100
On Friday 20 January 2006 09:00, Stephen Smith wrote:
[...]
> The flaw with this, as I mentioned, is that if the player holds down
> a key, then with so many keypress/release events being fired for the
> duration it is held down, the key might not be marked as being
> pressed at the time when the keys are being processed in the main
> game loop.
>
> Can anyone tell me what I'm missing? Or should I just move to
> another language? ;-) Any help will be much appreciated.
Well, it's not the language that's at fault - but that implementation
seems rather broken. One *has* to be able to tell "fake" (repeat)
events from real "key down" events to do this kind of stuff reliably.
Unfortunately, unless you're using som odd, known-to-be-broken
version, I don't think you can get around the problem.
Anyway, unless there is some way around this (does the API provide a
way of disabling the key repeat, or at least the events?), you may
sort of work around it with a simple filter. Keep a downcounter
(counting ms or something) for each key state. Reset the counter to a
suitable value (should really be the repeat interval) when you get a
key down event. The tcounter counts down when the key is not pressed,
and holds when the key is pressed. When a counter is non-zero, the
"real" key state is assumed to be "down".
The bad news is that you have to figure out the key repeat rate, and
that this filter will add latency to the key release events. I don't
think it gets much better than that without solving the real problem,
though.
//David Olofson - Programmer, Composer, Open Source Advocate
.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
'-- http://www.reologica.se - Rheology instrumentation --'
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- References:
- [gameprogrammer] Key Repeat problem
- From: Stephen Smith
- [gameprogrammer] Re: Key Repeat problem
- From: Simon Mihevc
- [gameprogrammer] Re: Key Repeat problem
- From: Stephen Smith
Other related posts:
- » [gameprogrammer] Key Repeat problem
- » [gameprogrammer] Re: Key Repeat problem
- » [gameprogrammer] Re: Key Repeat problem
- » [gameprogrammer] Re: Key Repeat problem
- » [gameprogrammer] Re: Key Repeat problem
- » [gameprogrammer] Re: Key Repeat problem
- » [gameprogrammer] Re: Key Repeat problem
- » [gameprogrammer] Re: Key Repeat problem
- » [gameprogrammer] Re: Key Repeat problem
- » [gameprogrammer] Re: Key Repeat problem
- » [gameprogrammer] Re: Key Repeat problem
- » [gameprogrammer] Re: Key Repeat problem
- » [gameprogrammer] Re: Key Repeat problem
- » [gameprogrammer] Re: Key Repeat problem
- » [gameprogrammer] Re: Key Repeat problem
- » [gameprogrammer] Re: Key Repeat problem
- » [gameprogrammer] Re: Key Repeat problem
- » [gameprogrammer] Re: Key Repeat problem
- » [gameprogrammer] Re: Key Repeat problem
- » [gameprogrammer] Re: Key Repeat problem
- » [gameprogrammer] Re: Key Repeat problem
- [gameprogrammer] Key Repeat problem
- From: Stephen Smith
- [gameprogrammer] Re: Key Repeat problem
- From: Simon Mihevc
- [gameprogrammer] Re: Key Repeat problem
- From: Stephen Smith