if its possible to catch KEY_ENTER_PAD "UP" message
thx
KEY_8_PAD?
Your question is not very clear. I understand that you want to respond to the event of the ENTER key of the numerical PAD being released, like an on_key_up event, is that right?
This is what I usually do in that case:
| 1 | |
| 2 | static int key_state[KEY_MAX]; |
| 3 | |
| 4 | int is_key_released(int key_index) { |
| 5 | int released = 0; |
| 6 | |
| 7 | if (key[key_index]) { |
| 8 | // key is pressed, store its state and return 0 |
| 9 | key_state[key_index] = 1; |
| 10 | } else { |
| 11 | // key is released, check the stored state, |
| 12 | // if it's zero, the key was never pressed, |
| 13 | // if it's one, the key was pressed in the previous iteration, so it was just released |
| 14 | released = key_state[key_index]; |
| 15 | // reset the stored state |
| 16 | key_state[key_index] = 0; |
| 17 | } |
| 18 | |
| 19 | return released; |
| 20 | } |
| 21 | |
| 22 | // use it to handle the event: |
| 23 | if (is_key_released(KEY_PAD_ENTER)) { |
| 24 | on_key_pad_enter_released(); |
| 25 | } |
Have a look at the keyboard call back functions, particularly 'keyboard_lowlevel_callback'
http://www.allegro.cc/manual/api/keyboard-routines/keyboard_lowlevel_callback
or if if you are in your main program loop try something like this
| 1 | #include <allegro.h> |
| 2 | |
| 3 | int main(int argc, char **argv) |
| 4 | { |
| 5 | allegro_init(); |
| 6 | install_keyboard(); |
| 7 | |
| 8 | set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0); |
| 9 | |
| 10 | int key_down = false; |
| 11 | int down_count = 0; |
| 12 | int up_count = 0; |
| 13 | |
| 14 | while(!key[KEY_ESC]) |
| 15 | { |
| 16 | if (key[KEY_ENTER_PAD]) |
| 17 | { |
| 18 | if (!key_down) |
| 19 | { |
| 20 | /* ran once when the key is pressed down */ |
| 21 | down_count++; |
| 22 | key_down = true; |
| 23 | } |
| 24 | } |
| 25 | else |
| 26 | { |
| 27 | if (key_down) |
| 28 | { |
| 29 | /* ran once when the key is released */ |
| 30 | up_count++; |
| 31 | key_down = false; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | textprintf_ex(screen, font, 0, 0, makecol(255,255,255), makecol(0,0,0), "Times KEY_ENTER_PAD has been pushed: %d", down_count); |
| 36 | textprintf_ex(screen, font, 0, 8, makecol(255,255,255), makecol(0,0,0), "Times KEY_ENTER_PAD has been released: %d", up_count); |
| 37 | |
| 38 | |
| 39 | } |
| 40 | |
| 41 | } |
| 42 | END_OF_MAIN() |
Edit: doh I was too slow