problème avec getch() ---> et les touches spéciales

problème avec getch() ---> et les touches spéciales - C++ - Programmation

Marsh Posté le 26-05-2002 à 23:37:02    

voilà le bout de code en question qui se situe à l'intérieur d'un while :
  char choix
  ...
  choix = getch();
  if (choix == 0) choix=getch();
  printf("touche : %x\n\n", choix);
 
 
et j'obtiens comme résultat quand je tape sur la touche flèche gauche:
 
touche : ffffffe0h
touche : 4bh
 
mais quand je tape sur la touche A par exemple j'obtiens bien :
touche :  
touche : 41h   (ce qui est donc tout à fait normal)
 
bref je comprends pas pourquoi j'ai droit à deux fois "touche : ...." quand j'utilise les touces spéciales comme les fléches ou f11 et f12, etc MAIS pas F1 à F10 et surtout pourquoi j'ai droit à "ffffffe0" à chaque fois que j'utilise ces touches !


---------------

Reply

Marsh Posté le 26-05-2002 à 23:37:02   

Reply

Marsh Posté le 27-05-2002 à 00:21:18    

e0 indique que le caractère suivant et un code étendu je pense...

Reply

Marsh Posté le 27-05-2002 à 00:28:56    

en fait en faisant :  
 
if (getch()) choix=getch();
else choix=getch();
printf("touche : %x\n\n", choix);
 
 
ça marche. si quelqu'un pouvait m'expliquer sur ce coup là je serais bien content !!


---------------

Reply

Marsh Posté le 27-05-2002 à 19:48:52    

les fleches et les autres touches spécial renvoient DEUX code !
 
le premier c'est (je croi) 0
le second c'est le code de la touche
 
donc :
 
premiercode=getch()  
if premiercode==0 secondcode=getch()  
 
te permet de tout recuperer comme y faut
 
elle te va mon explication ? ;)


---------------
Signatures aux choix Votez:  O - Le python c'est bon, mangez-en  O - L'abus de forum rend dependant, postez avec modération
Reply

Marsh Posté le 27-05-2002 à 20:13:44    

Code :
  1. if (getch()) choix=getch();
  2. else choix=getch();
  3. printf("touche : %x\n\n", choix);


 
ha hem ... je pense que tu t'es trompé ... vu que le if...else ne sert à rien ...
 

Code :
  1. choix = getch();
  2. if(choix == 0) choix=getch();
  3. printf("touche : %x\n\n", choix);


---------------
FAQ fclc++ - FAQ C++ - C++ FAQ Lite
Reply

Marsh Posté le 28-05-2002 à 18:06:14    

HelloWorld a écrit a écrit :

 
choix = getch();
if(choix == 0) choix=getch();  
 
printf("touche : %x\n\n", choix);




 
on est d'accord je croi

 

[jfdsdjhfuetppo]--Message édité par Phod le 28-05-2002 à 18:06:52--[/jfdsdjhfuetppo]


---------------
Signatures aux choix Votez:  O - Le python c'est bon, mangez-en  O - L'abus de forum rend dependant, postez avec modération
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed