Tuesday, December 6, 2011

C++ Program to pick the scan codes from a keyboard




  1. /* This program shows how to pick up the scan codes from a keyboard */




  2. /* These define the scan codes(IBM) for the keys. All numbers are in decimal.*/


  3. #define PAGE_UP 73


  4. #define HOME 71


  5. #define END 79


  6. #define PAGE_DOWN 81


  7. #define UP_ARROW 72


  8. #define LEFT_ARROW 75


  9. #define DOWN_ARROW 80


  10. #define RIGHT_ARROW 77


  11. #define F1 59


  12. #define F2 60


  13. #define F3 61


  14. #define F4 62


  15. #define F5 63


  16. #define F6 64


  17. #define F7 65


  18. #define F8 66


  19. #define F9 67


  20. #define F10 68


  21. #include <iostream>


  22. #include <conio.h>




  23. using namespace std;




  24. int main()


  25. {


  26. char KeyStroke;




  27. cout << "Press Escape to quit." << endl;




  28. do


  29. {


  30. KeyStroke = getch();




  31. if (KeyStroke == 0)


  32. {


  33. KeyStroke = getch(); // Even though there are 2 getch() it reads one keystroke


  34. switch (KeyStroke)


  35. {


  36. case PAGE_UP:


  37. cout << "PAGE UP" << endl;


  38. break;


  39. case PAGE_DOWN:


  40. cout << "PAGE DOWN" << endl;


  41. break;


  42. case HOME:


  43. cout << "HOME" << endl;


  44. break;


  45. case END:


  46. cout << "END" << endl;


  47. break;


  48. case UP_ARROW:


  49. cout << "UP ARROW" << endl;


  50. break;


  51. case DOWN_ARROW:


  52. cout << "DOWN ARROW" << endl;


  53. break;


  54. case LEFT_ARROW:


  55. cout << "LEFT_ARROW" << endl;


  56. break;


  57. case RIGHT_ARROW:


  58. cout << "RIGHT_ARROW" << endl;


  59. break;


  60. case F1:


  61. cout << "F1" << endl;


  62. break;


  63. case F2:


  64. cout << "F2" << endl;


  65. break;


  66. case F3:


  67. cout << "F3" << endl;


  68. break;


  69. case F4:


  70. cout << "F4" << endl;


  71. break;


  72. case F5:


  73. cout << "F5" << endl;


  74. break;


  75. case F6:


  76. cout << "F6" << endl;


  77. break;


  78. case F7:


  79. cout << "F7" << endl;


  80. break;


  81. case F8:


  82. cout << "F8" << endl;


  83. break;


  84. case F9:


  85. cout << "F9" << endl;


  86. break;


  87. case F10:


  88. cout << "F10" << endl;


  89. break;


  90. default:


  91. cout << "Some other key." << endl;


  92. }


  93. }


  94. else


  95. cout << KeyStroke << endl;


  96. }


  97. while (KeyStroke != 27); // 27 = Escape key


  98. }


No comments:

Post a Comment