Showing posts with label Detect or Recognize Arrow Keys in C Program. Show all posts
Showing posts with label Detect or Recognize Arrow Keys in C Program. Show all posts

Saturday, December 12, 2015

To Detect or Recognize Arrow Keys in C Program


Program #23

Description:
To Detect/Recognize Arrow Keys in C Program


/* Program to Detect Arrow Keys in C Program
UP Arrow    - 72
DOWN Arrow  - 80
LEFT Arrow  - 75
RIGHT Arrow - 77
*/

void main(){
  char inputKey, arrowKey;

 /* Clear the Screen */
  clrscr();
 
/* Detect Arrow Keys in C Program
     Press ESCAPE - 27 to
     Get out from the Indefinite loop
  */
  while ( (inputKey = getch()) != 27){

  /* Find Arrow Key or not */
    if (inputKey == '\0'){
     
/* Extract actual Arrow Key */
      arrowKey = getch();
      switch(arrowKey){
 case 72: printf("UP"); break;
 case 80: printf("DOWN"); break;
 case 75: printf("LEFT"); break;
 case 77: printf("RIGHT"); break;
      }
    }
  }
}



 

Popular Posts