Bonjour,
Je veux faire un simple et bête programme qui me permet d'obtenir les informations sur les boutons lorsque j'appuie dessus.
Seulement voilà, les premières infos s'effectuent sans problème, en revanche arrivé au stade 'évènement' , je n'ai pas de sortie lorsque j'appuie sur un bouton de ma manette.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #include <stdio.h> #include <stdlib.h> #include <SDL.h> void pause(); int main(int argc,char **argv) { int i; SDL_Joystick *joystick = NULL; SDL_Init(SDL_INIT_JOYSTICK); printf("Il y a %d joysticks détectés\n", SDL_NumJoysticks()); for(i=0;i<SDL_NumJoysticks();i++) printf("----> %d = %s\n",i,SDL_JoystickName(i)); SDL_JoystickEventState(SDL_ENABLE); joystick = SDL_JoystickOpen(0); printf("\n"); printf("----> %d boutons\n", SDL_JoystickNumButtons(joystick)); printf("----> %d axes\n", SDL_JoystickNumAxes(joystick)); pause(); SDL_JoystickClose(joystick); SDL_Quit(); return EXIT_SUCCESS; } void pause() { int continuer = 1; SDL_Event event; while (continuer) { SDL_WaitEvent(&event); switch(event.type) { case SDL_QUIT: continuer = 0; break; case SDL_JOYBUTTONDOWN: printf("Bouton N°%d\n",event.jbutton.button); break; default: break; } } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 daedalus11@debian:~/projets/sdzSDL$ ./sdzSDL Il y a 4 joysticks détectés ----> 0 = Xbox 360 Wireless Receiver ----> 1 = Xbox 360 Wireless Receiver ----> 2 = Xbox 360 Wireless Receiver ----> 3 = Xbox 360 Wireless Receiver ----> 15 boutons ----> 6 axes ^C daedalus11@debian:~/projets/sdzSDL$
D'autant plus comme vous pouvez le constater, il me détecte 4 joysticks alors que j'en ai qu'un.
Pour arrêter la boucle je dois faire un Ctrl+C .
Une idée du pourquoi mon printf() ne fait pas son effet dans la boucle d'évènements?
Partager