1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| #include <allegro5/allegro.h>
#include <allegro5/allegro_native_dialog.h>
void erreur(const char*txt)
{
ALLEGRO_DISPLAY*d;
d = al_is_system_installed() ? al_get_current_display() : NULL;
al_show_native_message_box(d, "ERREUR", txt, NULL, NULL, 0);
exit(EXIT_FAILURE);
}
bool Debug = 1;
/*****************************************************************
*****************************************************************/
int main()
{
ALLEGRO_DISPLAY*display;
ALLEGRO_KEYBOARD_STATE key;
ALLEGRO_TEXTLOG*console = NULL;
ALLEGRO_EVENT_QUEUE *queue;
//ALLEGRO_EVENT_QUEUE* queue; //file d'attente des evenements
if (!al_init())
erreur("al_init()");
if (Debug) //ouvre la console debug seulement si DEBUG = 1
console = al_open_native_text_log("Debug Console", 0);
al_append_native_text_log(console, "*** Bienvenue dans la console de Debug ***\n");
if (!al_install_keyboard())
erreur("al_install_keyboard()");
else al_append_native_text_log(console,"keyboard init\n");
//CREATION DE LA QUEUE
queue = al_create_event_queue();
if (!queue)
erreur ("al_create_event_queue()");
else al_append_native_text_log(console,"queue init\n");
//SOURCE DE LA QUEUE
al_register_event_source(queue, al_get_keyboard_event_source());
display = al_create_display(800, 600);
if (!display)
erreur("al_create_display()");
else al_append_native_text_log(console,"Display init\n");
al_clear_to_color(al_map_rgb(0,0,0));
al_flip_display();
do {
al_get_keyboard_state(&key);
}
while (!al_key_down(&key, ALLEGRO_KEY_ESCAPE));
{
ALLEGRO_EVENT event = { 0 };
al_wait_for_event_timed(queue, &event, 1.0 / 10);
//RECUPERATION DE LA TOUCHE ET AFFICHAGE
if(!al_key_down(&key, ALLEGRO_EVENT_KEY_CHAR));
//LA FRAPPE N'EST DETECTEE QUE POUR LA TOUCHE ESC !!! LE PROBLEME EST DANS LES PARAMETRES DE LA BOUCLE WHILE ?
//OU DANS LES PARAMETRES DE MON IF
{
//char *label = event.keyboard.repeat ?"repeat" : "KEY_CHAR";
const char *touche = al_keycode_to_name(event.keyboard.keycode);
al_append_native_text_log(console,"KEY CHAR DETECTED", touche,"\n");
}
}
al_rest(2.0);
al_destroy_display(display);
al_destroy_event_queue(queue);
return 0;
} |
Partager