Review key input queue PR #1012

Keeping original API
This commit is contained in:
raysan5 2019-11-24 13:39:45 +01:00
parent ae301a1d23
commit 1d3f230c92
3 changed files with 66 additions and 60 deletions

View file

@ -30,7 +30,7 @@ int main(void)
int framesCounter = 0;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
SetTargetFPS(10); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
@ -43,13 +43,20 @@ int main(void)
if (mouseOnText)
{
// Get pressed key (character) on the queue
int key = GetKeyPressed();
// NOTE: Only allow keys in range [32..125]
if ((key >= 32) && (key <= 125) && (letterCount < MAX_INPUT_CHARS))
// Check if more characters have been pressed on the same frame
while (key > 0)
{
name[letterCount] = (char)key;
letterCount++;
// NOTE: Only allow keys in range [32..125]
if ((key >= 32) && (key <= 125) && (letterCount < MAX_INPUT_CHARS))
{
name[letterCount] = (char)key;
letterCount++;
}
key = GetKeyPressed(); // Check next character in the queue
}
if (IsKeyPressed(KEY_BACKSPACE))