Skip to content

Commit

Permalink
Update rcore.c
Browse files Browse the repository at this point in the history
  • Loading branch information
nickyMcDonald committed Aug 20, 2023
1 parent 258ddbf commit 7004eeb
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/rcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -3746,12 +3746,10 @@ void OpenURL(const char *url)
//----------------------------------------------------------------------------------
// Module Functions Definition - Input (Keyboard, Mouse, Gamepad) Functions
//----------------------------------------------------------------------------------
#define KEY_SAFE(key) (((key) >= 0) && ((key) < sizeof(CORE.Input.Keyboard.currentKeyState)))

// Check if a key has been pressed once
bool IsKeyPressed(int key)
{
if (!KEY_SAFE(key)) return false;
if ((key < 0) || (key >= sizeof(CORE.Input.Keyboard.currentKeyState))) return false;
bool pressed = false;

if ((CORE.Input.Keyboard.previousKeyState[key] == 0) && (CORE.Input.Keyboard.currentKeyState[key] == 1)) pressed = true;
Expand All @@ -3762,15 +3760,15 @@ bool IsKeyPressed(int key)
// Check if a key is being pressed (key held down)
bool IsKeyDown(int key)
{
if (!KEY_SAFE(key)) return false;
if ((key < 0) || (key >= sizeof(CORE.Input.Keyboard.currentKeyState))) return false;
if (CORE.Input.Keyboard.currentKeyState[key] == 1) return true;
else return false;
}

// Check if a key has been released once
bool IsKeyReleased(int key)
{
if (!KEY_SAFE(key)) return false;
if ((key < 0) || (key >= sizeof(CORE.Input.Keyboard.currentKeyState))) return false;
bool released = false;

if ((CORE.Input.Keyboard.previousKeyState[key] == 1) && (CORE.Input.Keyboard.currentKeyState[key] == 0)) released = true;
Expand All @@ -3781,15 +3779,15 @@ bool IsKeyReleased(int key)
// Check if a key is NOT being pressed (key not held down)
bool IsKeyUp(int key)
{
if (!KEY_SAFE(key)) return false;
if ((key < 0) || (key >= sizeof(CORE.Input.Keyboard.currentKeyState))) return false;
if (CORE.Input.Keyboard.currentKeyState[key] == 0) return true;
else return false;
}

// Check if a key has been repeated
bool IsKeyRepeated(int key)
{
if (!KEY_SAFE(key)) return false;
if ((key < 0) || (key >= sizeof(CORE.Input.Keyboard.currentKeyState))) return false;
if (CORE.Input.Keyboard.repeatKeyState[key] == 1) return true;
else return false;
}
Expand Down

0 comments on commit 7004eeb

Please sign in to comment.