|
problem with keyboard events (KEY_UP and KEY_LEFT) |
zztop2000
Member #14,757
December 2012
|
Hi, (sorry for my English) I'm using Allegro 5.0.8 under Ubuntu 11.04 with Eclipse Indigo. I made a simple graphic object moved by pressing the arrow keys. Here the code inside a loop: 1 .
2 .
3 .
4while (!terminated)
5 {
6
7 al_wait_for_event(event_queue, &ev);
8
9 if (ev.type == ALLEGRO_EVENT_TIMER) {
10 .
11 <calculate the movement here>
12 .
13 redraw = true;
14
15 }
16 else if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
17 {
18 terminated = true;
19 }
20 else if (ev.type == ALLEGRO_EVENT_KEY_DOWN)
21 {
22
23 switch (ev.keyboard.keycode)
24 {
25 case ALLEGRO_KEY_UP:
26 key[0] = true;
27 break;
28 case ALLEGRO_KEY_DOWN:
29 key[1] = true;
30 break;
31 case ALLEGRO_KEY_LEFT:
32 key[2] = true;
33 break;
34 case ALLEGRO_KEY_RIGHT:
35 key[3] = true;
36 break;
37 }
38 }
39 else if (ev.type == ALLEGRO_EVENT_KEY_UP)
40 {
41
42 switch (ev.keyboard.keycode)
43 {
44 case ALLEGRO_KEY_UP:
45 key[0] = false;
46 break;
47 case ALLEGRO_KEY_DOWN:
48 key[1] = false;
49 break;
50 case ALLEGRO_KEY_LEFT:
51 key[2] = false;
52 break;
53 case ALLEGRO_KEY_RIGHT:
54 key[3] = false;
55 break;
56 }
57 }
58 if(redraw && al_is_event_queue_empty(event_queue))
59 {
60 redraw = false;
61 .
62 .
63 .
64 }
The KEY_UP state is correctly updated to FALSE when i release the key but the KEY_LEFT continues to have the TRUE value. Debugging the application i saw that the "ev.keyboard.keycode" take only the first code (84 - KEY_UP), ignoring the second keycode (82 - KEY_LEFT). In all the other case (upper-right, lower-left, lower-right) the "ev.keyboard.keycode" works correctly taking both the keycodes and setting them to FALSE (obviously, because is a simple int, the second keycode appears after the second call to the function "al_wait_for_event()"). Has anyone encountered this problem? |
torhu
Member #2,727
September 2002
|
You could try ex_keyboard_events and see if the same thing happens there. It's even possible that this is a limitation of your keyboard, but hopefully it's just a bug in your code. |
zztop2000
Member #14,757
December 2012
|
Thanks for the reply. I tried with an external keyboard now and it works. So, this is a hardware problem as you suggest. |
|