does anybody know how to get all currently pressed keys?
I have a function called getMouseButtons which does this..
and I( was trying to make a keyboard version..
the problem is ALLEGRO_KEYBOARD_STATE doesn't have a member called keys like ALLEGRO_MOUSE_STATE has a member called buttons.
With ALLEGRO_KEYBOARD_STATE you have to use function called al_key_down ( https://www.allegro.cc/manual/5/al_key_down ) to read a single key.
Otherwise if the function alone is not sufficient and you would like to always have something similar to the mouse buttons variable then you will need to create an array of keys and update it yourself by reading each key. Something along the lines of:
bool pressed_key[ALLEGRO_KEY_MAX]; ... al_get_keyboard_state(&kbdstate); for (int i=0; i<ALLEGRO_KEY_MAX; ++i) { if (al_key_down(&kbdstate, i)) pressed_key[i] = true; else pressed_key[i] = false; }
Polling is outdated, and honestly shouldn't have been included in A5. :/
The proper way to monitor the state of the keyboard and mouse is through the event system.
If you poll, you stand the risk of losing events in-between polls.
Some example code to get you started :
can events be used in a way that I can do..
key_is_down()
key_is_held()
key_is_up ()
I would rather not have to keep my game logic in main's events
Yes.
You can use pointers, you can pass variables, you can do whatever you want.
Hint (you only need one event loop)
hmm ok I think I am going to go with this..