Re: [AD] keyboard buffer (proposal)

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Sat, 2008-12-20 at 16:17 -0600, Matthew Leverton wrote:
> On Sat, Dec 20, 2008 at 3:06 PM, Elias Pschernig
> <elias.pschernig@xxxxxxxxxx> wrote:
> > My vote is to completely remove ALLEGRO_KEYBOARD_STATE and al_key_down.
> >
> > It's not easier to use than events, and means you randomly lose key
> > presses whenever the user starts typing/playing fast. So basically as
> > soon as you use them, your game is broken. There's simply no reason at
> > all to ever use them.
> >
> I disagree. And plus, as SiegeLord pointed out, using events could
> break your game too.
> 
> However, I wouldn't mind removing ALLEGRO_KEYBOARD_STATE from the
> programmer's view. How would people use it, other than:
> 
> al_poll_keyboard();
> if (al_key_down(ALLEGRO_KEY_LEFT)) p.x--;

What about at least changing the return value of al_key_down slightly?

x = al_key_down(ALLEGRO_KEY_LEFT)

x = 0 not pressed, not released since last call to al_poll_keyboard
x = 1 currently pressed, not released
x = 2 not pressed, but released one or more times
x = 3 currently pressed, and additionally released at least once

It doesn't solve the problem of lost keys, but at least now you know
when you might have lost keys (return 2 and 3).

> 
> However, the polling API (al_key_down) would prevent that problem,
> since (as far as I know) it actually reads the current key state.
> 

Not in X11. Whether you use events or state, your window will not get
the key release event and so the key never is seen as released.

The solution is simple of course, just check for the focus lost event if
you use event. In the case of keyboard state, I think we had code to
clear the complete state when focus is lost, maybe that needs to be put
back (or maybe it already is).

-- 
Elias Pschernig <elias@xxxxxxxxxx>





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/