Answer to Question #258334 in Java | JSP | JSF for Charmaine

Question #258334

Write a program that check and classify buttons pressed on the keyboard.


After pressing any button, the program


should display one of labels: - lowercase letter


- capital letter


- digit


- ENTER


- ESC


- Left Arrow


- Right arrow


- F1 function key


- Another (unrecognised) key


HINT: to retrieve the keyboard key code, use function getch() from the library <conio.h>.


1
Expert's answer
2021-10-29T07:19:57-0400


SAMPLE PROGRAM OUTPUT






#include<iostream>


#include<conio.h>


using namespace std;


int main()


{


  char key_press;


  int ascii_value;


  cout<<"\t\t\tPress Button on the keyboard\n\n\n";
 
  while(1)


  {


  key_press=getch();


  ascii_value=key_press;
  cout<<"\t\t\tKEY Pressed-> is "<<key_press<<"<<key_press Ascii Value =  "<<ascii_value<<endl;


  if(ascii_value == 77)


{


cout<<"\t\t\tRight arrow key"<<endl;


}


else if(ascii_value == 75)


{


cout<<"\t\t\tLeft Arrow key"<<endl;


}


  else if(ascii_value>=65 && ascii_value<=90)


  {


   cout<<"\t\t\tcapital letter"<<endl;


}


else if(ascii_value>=97 && ascii_value<=122)


{


cout<<"\t\t\tLowercase letter"<<endl;


}


else if(ascii_value>=48 && ascii_value<=57)


{


cout<<"\t\t\tDigit"<<endl;


}


  else if(ascii_value==27) // For ESC


  {


   cout<<"\t\t\tESC key"<<endl;


}


  else if(ascii_value==13)


  {


   cout<<"\t\t\tEnter key"<<endl;


}


else if(ascii_value == 359)


{


cout<<" F1 function key"<<endl;


}


else


{


cout<<"\t\t\tAnother (unrecognised) key"<<endl;


}


  
  }


  return 0;


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS