Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. /*
  2. * Keyboard.h
  3. *
  4. * Created on: 18 jun. 2019
  5. * Author: Gebruiker
  6. */
  7.  
  8. #include <windows.h>
  9. #include <stdio.h>
  10. #include <conio.h>
  11.  
  12. typedef struct KeyboardState {
  13. int quit;
  14. int left;
  15. int right;
  16. int up;
  17. int down;
  18. int no;
  19. } KeyboardState;
  20.  
  21. KeyboardState getKeyboardState() {
  22. KeyboardState state = { 0 };
  23.  
  24. int ch;
  25. int add;
  26.  
  27. state.quit = ((ch = _getch()) == 27) /* 27 = Esc key */;
  28.  
  29. if (ch == 0 || ch == 224) {
  30.  
  31. add = _getch();
  32.  
  33. state.up = ((add == 72));
  34. state.left = ((add == 75));
  35. state.right = ((add == 77));
  36. state.down = ((add == 80));
  37.  
  38. }
  39. state.no = 1;
  40.  
  41. return state;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement