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