Beginners_-_GetKeyPressed_Buffer.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "raylib.h"
  2. int main(void)
  3. {
  4. // Initialization
  5. //--------------------------------------------------------------------------------------
  6. const int screenWidth = 800;
  7. const int screenHeight = 450;
  8. InitWindow(screenWidth, screenHeight, "raylib example.");
  9. SetTargetFPS(5); // Set our game to run at 5 frames-per-second
  10. //--------------------------------------------------------------------------------------
  11. int keypressedcount=0;
  12. // Main game loop
  13. while (!WindowShouldClose()) // Detect window close button or ESC key
  14. {
  15. // Update
  16. //----------------------------------------------------------------------------------
  17. // See if the keyboard has been used.
  18. int key = GetKeyPressed(); // read/remove key from buffer.
  19. // Here we count how many keys are inside the buffer. (set framerate to low for effect!)
  20. int len = 0;
  21. while(key>0){
  22. len++;
  23. key = GetKeyPressed();// get/remove key from buffer.
  24. }
  25. //----------------------------------------------------------------------------------
  26. // Draw
  27. //----------------------------------------------------------------------------------
  28. BeginDrawing();
  29. ClearBackground(RAYWHITE);
  30. // Draw our info.
  31. DrawText("Quickly hammer on the keyboard to fill up the keyboard buffer.",100,200,20,GRAY);
  32. DrawText(FormatText("GetKeyPressed() buffer length : %i",len),100,100,20,RED);
  33. EndDrawing();
  34. //----------------------------------------------------------------------------------
  35. }
  36. // De-Initialization
  37. //--------------------------------------------------------------------------------------
  38. CloseWindow(); // Close window and OpenGL context
  39. //--------------------------------------------------------------------------------------
  40. return 0;
  41. }