648trindade
648trindade

Reputation: 748

Bug on key up events in allegro

I'm doing a homework of my course using Allegro, as ordered.

I need to catch the key up events on keyboard, for this I used the follow code:

al_wait_for_event(evento, &ev);
if(ev.type == ALLEGRO_EVENT_KEY_UP){
   if (ev.keyboard.keycode==ALLEGRO_KEY_A || ev.keyboard.keycode==ALLEGRO_KEY_LEFT)
       cmd='a';
   else if (ev.keyboard.keycode==ALLEGRO_KEY_W || ev.keyboard.keycode==ALLEGRO_KEY_UP)
            cmd='w';
   else if (ev.keyboard.keycode==ALLEGRO_KEY_D || ev.keyboard.keycode==ALLEGRO_KEY_RIGHT)
            cmd='d';
   else if (ev.keyboard.keycode==ALLEGRO_KEY_S || ev.keyboard.keycode==ALLEGRO_KEY_DOWN)
            cmd='s';
}

But this event return the value 6 times​​ at once!

On the code I have included (previously) this commands:

al_install_keyboard();
[...]
al_register_event_source(evento, al_get_keyboard_event_source());

Where am I wrong?

Upvotes: 0

Views: 337

Answers (1)

PedroCordeiro
PedroCordeiro

Reputation: 76

Before the ALLEGRO_EVENT_KEY_UP event, there will be the ALLEGRO_EVENT_KEY_DOWN.

Just change UP to DOWN and it'll do.

Upvotes: 1

Related Questions