Advertisement
EconomicSerg

Keyboard Input

Sep 5th, 2021
551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. #define W 119
  5. #define A 97
  6. #define S 115
  7. #define D = 100
  8.  
  9. int main()
  10. {
  11.     int key = getch();
  12.    
  13.     // Uncomment this if you would like to know keys
  14.     // Simply uncomment this, comment the switch, run the program, and just press keys to get an integer value
  15.     // Make a #define statement, give it a name of the key, and give it an integer value of the key.
  16.     // e.g. W = 119
  17.     /*
  18.     std::cout << key << "\n\n";
  19.     */
  20.    
  21.     switch(key)
  22.     {
  23.         case W:
  24.             std::cout << "W was pressed\n\n";
  25.             break;
  26.         case A:
  27.             std::cout << "A was pressed\n\n";
  28.             break;
  29.         case S:
  30.             std::cout << "S was pressed\n\n";
  31.             break;
  32.         case D:
  33.             std::cout << "D was pressed\n\n";
  34.             break;
  35.     }
  36.    
  37.     std::cin.get(); // Used to see the output window. Just in case
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement