00_press_any_key.cpp 692 B

123456789101112131415161718192021222324252627282930313233343536373839
  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 any key!");
  15. while(true)
  16. if (auto e = next_event(); !e || !std::holds_alternative<key_pressed>(*e))
  17. std::this_thread::sleep_for(20ms);
  18. else break;
  19. return 0;
  20. }
  21. catch(...)
  22. {
  23. if(errno)
  24. std::perror("ERROR");
  25. const char* sdl_error = SDL_GetError();
  26. if(*sdl_error)
  27. std::puts(sdl_error);
  28. throw;
  29. }