Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » problem with keypressed function

This thread is locked; no one can reply to it. rss feed Print
problem with keypressed function
William Labbett
Member #4,486
March 2004
avatar

Hi,

I'm just trying to get a wait for keypress function working and when I run

my program with this code and a call to it, the console window does print

"Waiting for event."

but when I press a key, the program doesn't continue. Can anyone help?

#SelectExpand
1int wait_for_keypress() 2{ 3 ALLEGRO_EVENT_QUEUE *queue = NULL; 4 ALLEGRO_EVENT event; 5 6 7 queue = al_create_event_queue(); 8 if(queue == NULL) 9 { 10 return 0; 11 } 12 13 al_register_event_source(queue, al_get_keyboard_event_source()); 14 15 do 16 { 17 cout << "waiting for event.\n"; 18 al_wait_for_event(queue, &event); 19 20 } while( event.type != ALLEGRO_EVENT_KEY_DOWN ); 21 22 cout << "got key down"; 23 24 al_destroy_event_queue(queue); 25 26 return 1; 27}

SiegeLord
Member #7,827
October 2006
avatar

Did you create a display beforehand?

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

torhu
Member #2,727
September 2002
avatar

Did you call al_install_keyboard?

William Labbett
Member #4,486
March 2004
avatar

I do create a display but after I've installed the keyboard. Is that the wrong thing to do?

Go to: