Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » Controller button input version 5.22

This thread is locked; no one can reply to it. rss feed Print
Controller button input version 5.22
TripleG
Member #16,431
July 2016

The input response for

if (events.type == ALLEGRO_EVENT_JOYSTICK_BUTTON_DOWN)
{
printf("Button was pressed\n");
}
else if (events.type == ALLEGRO_EVENT_JOYSTICK_BUTTON_UP)
{
printf("Button was released\n");
}

is really bad. Sometimes it even skips that the button was released. It improved when I used al_wait_for_event(event_queue, &events);

but there are still skips when the buttons are pressed when I press the buttons too fast. Even when I press them at slow intervals it sometimes skips Button was released. I am using ALLEGRO_5.22 and have it installed using Microsoft visual studio 2015. Keyboard responses are immediate and analog response are immediate with controllers. It is just the buttons that are the issue

SilverTES
Member #16,572
October 2016

I have the same problem , but I don't found a solution.
Meantime, I use SFML window module with Allegro, sf::Joystick the response is better.

Eric Johnson
Member #14,841
January 2013
avatar

Like I mentioned in your other topic, I haven't noticed any issues with the joystick API. Here is the example I threw together again:

#SelectExpand
1#include <iostream> 2 3#include <allegro5/allegro.h> 4 5using std::cout; 6 7int main(void) { 8 9 if (!al_init()) { 10 11 cout << "Error: failed to initialize Allegro\n"; 12 13 return -1; 14 } 15 16 if (!al_install_joystick()) { 17 18 cout << "Error: failed to install joystick\n"; 19 20 return -1; 21 } 22 23 ALLEGRO_TIMER *timer; 24 ALLEGRO_EVENT_QUEUE *event_queue; 25 26 if (!(timer = al_create_timer(1.0 / 60.0))) { 27 28 cout << "Error: failed to create timer\n"; 29 30 return -1; 31 } 32 33 if (!(event_queue = al_create_event_queue())) { 34 35 cout << "Error: failed to create event_queue\n"; 36 37 return -1; 38 } 39 40 al_register_event_source(event_queue, al_get_joystick_event_source()); 41 al_register_event_source(event_queue, al_get_timer_event_source(timer)); 42 43 al_start_timer(timer); 44 45 cout << "Notice: press joystick buttons now (program will shutdown in 20 seconds)\n\n"; 46 47 while (true) { 48 49 ALLEGRO_EVENT event; 50 51 al_wait_for_event(event_queue, &event); 52 53 if (event.type == ALLEGRO_EVENT_TIMER) { 54 55 static unsigned int ticks = 0; 56 57 ++ticks; 58 59 if (ticks > 60 * 20) { 60 61 break; 62 } 63 } 64 65 if (event.type == ALLEGRO_EVENT_JOYSTICK_BUTTON_DOWN) { 66 67 cout << "Button pressed\n"; 68 } 69 else if (event.type == ALLEGRO_EVENT_JOYSTICK_BUTTON_UP) { 70 71 cout << "Button released\n"; 72 } 73 } 74 75 al_destroy_timer(timer); 76 al_destroy_event_queue(event_queue); 77 78 cout << "\nGood bye!\n"; 79 80 return 0; 81}

The above works for me without issue. I encourage others to test it out and see how it works for them.

Neil Roy
Member #2,229
April 2002
avatar

I had similar issues with an older version of Allegro 5, I forget which exactly, 5.1 maybe? My main problem I had was with the digital joystick input when I used my Microsoft controller, like the XBox style controllers or whatever. Analog seemed okay, but I had issues with the digital joystick inputs. I worked on it for a very long time before finally removing support for Joysticks from my game (Deluxe Pacman 2).

My problems were, if you were going one direction, and changed directions, it would often wouldn't pick it up at all unless you centered the stick first (or let go of it) then push the new direction. For digital this was a pain as that is the main input my game uses. Analog worked okay as I remember. I may have to check my notes again. I worked long and hard on this until I eventually just commented out all the joystick code.

Sounds like the same issues are still there.

---
“I love you too.” - last words of Wanda Roy

Go to: