|
best way to handle multiple keypresses |
Neil Walker
Member #210
April 2000
|
I ripped some code from one of the examples, but it only works when you have one key pressed at a time, i.e. if (event.type == ALLEGRO_EVENT_KEY_CHAR) { if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) break; if (event.keyboard.keycode==ALLEGRO_KEY_LEFT) mapxoff-=MAPINCREMENT; if (event.keyboard.keycode==ALLEGRO_KEY_RIGHT) mapxoff+=MAPINCREMENT; if (event.keyboard.keycode==ALLEGRO_KEY_UP) mapyoff-=MAPINCREMENT; if (event.keyboard.keycode==ALLEGRO_KEY_DOWN) mapyoff+=MAPINCREMENT; } What's the A5 route, do you use another event or is there a global key array, etc? and what's the difference between EVENT_KEY_CHAR and KEY_UP/KEY_DOWN Thanks. Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
Edgar Reynaldo
Major Reynaldo
May 2007
|
al_get_keyboard_state and al_key_down will give you full information for which keys are down, so you can combine them. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Neil Walker
Member #210
April 2000
|
But those bypass events? Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
Thomas Fjellstrom
Member #476
June 2000
|
Just store your own key[] array. Then the keyboard events just fill in the key array, and your logic code accesses the key[] array instead. append: Of course you should be using the KEY_PRESS/RELEASE events instead as well. -- |
Audric
Member #907
January 2001
|
ALLEGRO_EVENT_KEY_CHAR is pretty much the same as using the keypressed() / readkey() interface from Allegro 4. These events are also the only good ones to get real text input: For example on French-located Windows I press: |
Matthew Leverton
Supreme Loser
January 1999
|
Neil Walker said: and what's the difference between EVENT_KEY_CHAR and KEY_UP/KEY_DOWN KEY_CHAR essentially means you can look at the unichar field. KEY_UP/KEY_DOWN represent physical key presses. One KEY_DOWN could translate to multiple KEY_CHARs. e.g., Maybe you have a macro set up such that F1 generates the keys f,o,o. Or multiple KEY_DOWNs could translate to a single KEY_CHAR. e.g., maybe pressing 'e (two KEY_DOWNs) gives a single KEY_CHAR é. |
Arthur Kalliokoski
Second in Command
February 2005
|
Does it handle PAUSE/BREAK? They all watch too much MSNBC... they get ideas. |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Thomas Fjellstrom said: Just store your own key[] array. Then the keyboard events just fill in the key array, and your logic code accesses the key[] array instead. Shouldn't this have the same results as if you used al_get_keyboard_state? Why do it yourself when Allegro 5 supposedly does it for you? My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Matthew Leverton
Supreme Loser
January 1999
|
The benefit of doing it yourself is that you are guaranteed to never miss a state change. If you use the Allegro state, then you may miss something if you don't check often enough. Even if you check the Allegro state when you receive a KEY_DOWN event, there's no guarantee that it is in sync with the event. |
Neil Walker
Member #210
April 2000
|
It works a treat. Thanks. Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
|