Re: [AD] keyboard buffer (proposal)

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


On 2008-12-20, Matthew Leverton <meffer@xxxxxxxxxx> wrote:
> 
> 2) key buffer
> 
> al_enable_key_buffer(true); // called once
> al_key_buffer_is_empty(); // i.e. A4's !keypressed()
> int scancode = al_read_key(&unichar, &modifiers); // parameters are optional.
> al_clear_key_buffer();
> 
> With this, Allegro 5 is as easy to use as 4 while still offering more
> flexible event queues. (I have no suggestions for joystick & mouse, as
> I think they are fine as is.)

I'm okay with adding the key buffer.

> +/* Function: al_read_key
> + *  Waits for a key press and returns the keycode.
> + *  If 'unichar' is not null, it will be updated with the
> + *  unichar representation of the key. If 'modifiers' is
> + *  not null, it will be updated with whatever modifiers
> + *  (e.g. SHIFT) were being pressed with the key.
> + *  Only works if <enable_key_buffer>() has been called.
> + */
> +int al_read_key(int *unichar, int *modifiers)
> +{
> +   ALLEGRO_EVENT event;
> +
> +   ASSERT(keyboard_queue != NULL);
>  
> +   do {
> +      al_wait_for_event(keyboard_queue, &event);
> +   } while (event.type == ALLEGRO_EVENT_KEY_UP);

You should accept ALLEGRO_EVENT_KEY_REPEAT as well.

Peter





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