Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <allegro.h>
- #include<time.h>
- #define ECRAN_X 800
- #define ECRAN_Y 600
- /******************************************************************************
- *******************************************************************************/
- int main()
- {
- int x, y, rx, ry, choix, done=0;
- allegro_init();
- install_keyboard();
- install_mouse();
- srand(time(NULL));
- set_color_depth(32);
- if (set_gfx_mode(GFX_AUTODETECT,ECRAN_X,ECRAN_Y,0,0)!=0){
- set_gfx_mode(GFX_TEXT,0,0,0,0);
- allegro_message(allegro_error);
- allegro_exit();
- return 1;
- }
- //----------------------------AFFICHAGE INFOS
- textprintf_ex(screen,font, 100, 80,makecol(0,0,255),-1,
- "Bouger la souris :");
- textprintf_ex(screen,font, 100, 120,makecol(0,0,255),-1,
- "Tester clics gauche et droit");
- textprintf_centre_ex(screen,font, SCREEN_W/2, 230,makecol(0,255,255),-1,
- "Il n'y a pas de raffraichissement de l'ecran");
- textprintf_ex(screen,font, 100, SCREEN_H-140,makecol(255,255,0),-1,
- "Touches fleches clavier : test clavier via scancodes,");
- textprintf_ex(screen,font, 100, SCREEN_H-130,makecol(255,255,0),-1,
- " (essayer plusieurs en meme temps)");
- textprintf_ex(screen,font, 100, SCREEN_H-120,makecol(255,255,0),-1,
- " Quitter avec SPACE");
- textprintf_ex(screen,font, 100, SCREEN_H-100,makecol(255,0,255),-1,
- "Touches F1, F2, F3, F4 : test clavier via buffer clavier");
- textprintf_ex(screen,font, 100, SCREEN_H-90,makecol(255,0,255),-1,
- " (essayer plusieurs en meme temps)");
- textprintf_ex(screen,font, 100, SCREEN_H-80,makecol(255,0,255),-1,
- " Quitter avec Echapp");
- //interdit la répétition de touche pour le buffer clavier
- set_keyboard_rate(0,0);
- // récupe en x et y de la position souris
- x=mouse_x;
- y=mouse_y;
- //----------------------------BOUCLE EVENTS
- while (!done){
- //-------------------------LA SOURIS
- // 1) les coordonnées
- if ( x!= mouse_x || y!=mouse_y){
- textprintf_ex(screen,font, 100, 100,makecol(0,0,0),-1, "%d %d", x,y);
- x=mouse_x;
- y=mouse_y;
- textprintf_ex(screen,font, 100, 100,makecol(0,255,0),-1, "%d %d", x,y);
- }
- // 2) les clics
- if (mouse_b & 1) // gauche
- rectfill(screen,x, y, x+20, y+20, makecol(255,0,0));
- if (mouse_b & 2) // droit
- rectfill(screen,x, y, x+20, y+20, makecol(0,0,255));
- if (mouse_b &4) // mileu ou les deux à la fois fin du programme
- done=1;
- //------------------------LE CLAVIER
- // méthode 1 : switch plus buffer clavier
- if (keypressed()){
- choix=readkey();
- // recupe de la valeur de scancode à partir du buffer clavier
- switch (choix>>8){
- case KEY_F1 :
- rectfill(screen,350 ,100 , 450, 200, makecol(rand()%255,0,255));
- break;
- case KEY_F2 :
- rectfill(screen,350 ,100 , 450, 200, makecol(0,255,rand()%255));
- break;
- case KEY_F3 :
- rectfill(screen,350 ,100 , 450, 200,makecol(255,rand()%255,0));
- break;
- case KEY_F4 :
- rectfill(screen,350 ,100 , 450, 200, makecol(0,0,0));
- break;
- case KEY_ESC : done=1; break;
- default : break;
- }
- }
- // clavier méthode 2 : if plus scancodes
- if (key[KEY_UP])
- rectfill(screen,350 ,270 , 450, 370, makecol(rand()%255,0,255));
- if (key[KEY_DOWN])
- rectfill(screen,350 ,270 , 450, 370, makecol(0,255,rand()%255));
- if (key[KEY_LEFT])
- rectfill(screen,350 ,270 , 450, 370, makecol(255,rand()%255,0));
- if (key[KEY_RIGHT])
- rectfill(screen,350 ,270 , 450, 370, makecol(0,0,0));
- if (key[KEY_SPACE])
- done=1;
- }
- exit(EXIT_SUCCESS);
- }
- END_OF_MAIN();
Add Comment
Please, Sign In to add comment