Beginners_-_MouseOrKeyDown.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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(60); // Set our game to run at 60 frames-per-second
  10. //--------------------------------------------------------------------------------------
  11. // Main game loop
  12. while (!WindowShouldClose()) // Detect window close button or ESC key
  13. {
  14. // Update
  15. //----------------------------------------------------------------------------------
  16. //----------------------------------------------------------------------------------
  17. // Draw
  18. //----------------------------------------------------------------------------------
  19. BeginDrawing();
  20. ClearBackground(RAYWHITE);
  21. // Here we test is mouse button 0 or 1 or 2 is down.
  22. if(IsMouseButtonDown(0)){
  23. DrawText("Mouse Button 0 is Down.",50,100,20,BLACK);
  24. }else{
  25. DrawText("Mouse Button 0 is NOT Down.",50,100,20,BLACK);
  26. }
  27. if(IsMouseButtonDown(1)){
  28. DrawText("Mouse Button 1 is Down.",50,120,20,BLACK);
  29. }else{
  30. DrawText("Mouse Button 1 is NOT Down.",50,120,20,BLACK);
  31. }
  32. if(IsMouseButtonDown(2)){
  33. DrawText("Mouse Button 2 is Down.",50,140,20,BLACK);
  34. }else{
  35. DrawText("Mouse Button 2 is NOT Down.",50,140,20,BLACK);
  36. }
  37. // Here we test if the space key is down.
  38. if(IsKeyDown(KEY_SPACE)){
  39. DrawText("KEY_SPACE is Down.",370,100,20,BLACK);
  40. }else{
  41. DrawText("KEY_SPACE is NOT Down.",370,100,20,BLACK);
  42. }
  43. // Here we test if any key is down.
  44. // Note that the value i<x might be higher than here.
  45. bool onedown=false;
  46. for(int i=0;i<355;i++){
  47. if(IsKeyDown(i)){
  48. DrawText(FormatText("IsKeyDown : %i",i),370,120,20,BLACK);
  49. onedown = true;
  50. }
  51. }
  52. if (onedown==false)DrawText("IsKeyDown : Nothing",370,120,20,BLACK);
  53. EndDrawing();
  54. //----------------------------------------------------------------------------------
  55. }
  56. // De-Initialization
  57. //--------------------------------------------------------------------------------------
  58. CloseWindow(); // Close window and OpenGL context
  59. //--------------------------------------------------------------------------------------
  60. return 0;
  61. }