02_press_hjkl.cpp 848 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include <cstdio>
  2. #include <thread>
  3. #include <chrono>
  4. #include "simple/interactive/initializer.h"
  5. #include "simple/interactive/event.h"
  6. #include "common/sdl_input_grabber.h"
  7. #include "common/sdl_input_grabber.cpp"
  8. using namespace simple::interactive;
  9. using namespace std::chrono_literals;
  10. int main() try
  11. {
  12. initializer init;
  13. sdl_input_grabber input_grabber;
  14. std::puts("Press H J or K L! (casue 2 keys is the limit for some keyoards!)");
  15. while(true)
  16. {
  17. next_event(); // update the key states
  18. if ((pressed(scancode::h) && pressed(scancode::j)) ||
  19. (pressed(scancode::k) && pressed(scancode::l)) ||
  20. pressed(scancode::escape))
  21. break;
  22. std::this_thread::sleep_for(20ms);
  23. }
  24. return 0;
  25. }
  26. catch(...)
  27. {
  28. if(errno)
  29. std::perror("ERROR");
  30. const char* sdl_error = SDL_GetError();
  31. if(*sdl_error)
  32. std::puts(sdl_error);
  33. throw;
  34. }