Ability to assign a new key for screen capture

Instead of hardcoding the screen capture key, it's assigned to a variable, and also added 2 simple get/set functions for the key.
This commit is contained in:
Hanaxar 2022-07-11 12:02:49 +03:00 committed by GitHub
parent b92573e711
commit d0788f6791
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -503,6 +503,7 @@ const char *raylibVersion = RAYLIB_VERSION; // raylib version symbol, it could b
static CoreData CORE = { 0 }; // Global CORE state context
#if defined(SUPPORT_SCREEN_CAPTURE)
static int screenCaptureKey = KEY_F12; // Default screen capture key: F12
static int screenshotCounter = 0; // Screenshots counter
#endif
@ -2775,6 +2776,20 @@ void SetConfigFlags(unsigned int flags)
// NOTE TRACELOG() function is located in [utils.h]
#if defined(SUPPORT_SCREEN_CAPTURE)
// Get current screen capture key
int GetScreenCaptureKey(void)
{
return key;
}
// Set screen capture key
void SetScreenCaptureKey(int key)
{
if (key > 0) screenCaptureKey = key;
}
#endif
// Takes a screenshot of current screen (saved a .png)
void TakeScreenshot(const char *fileName)
{
@ -5306,7 +5321,7 @@ static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, i
if ((key == CORE.Input.Keyboard.exitKey) && (action == GLFW_PRESS)) glfwSetWindowShouldClose(CORE.Window.handle, GLFW_TRUE);
#if defined(SUPPORT_SCREEN_CAPTURE)
if ((key == GLFW_KEY_F12) && (action == GLFW_PRESS))
if ((key == screenCaptureKey) && (action == GLFW_PRESS))
{
#if defined(SUPPORT_GIF_RECORDING)
if (mods == GLFW_MOD_CONTROL)
@ -6016,8 +6031,8 @@ static void ProcessKeyboard(void)
if (CORE.Input.Keyboard.currentKeyState[CORE.Input.Keyboard.exitKey] == 1) CORE.Window.shouldClose = true;
#if defined(SUPPORT_SCREEN_CAPTURE)
// Check screen capture key (raylib key: KEY_F12)
if (CORE.Input.Keyboard.currentKeyState[301] == 1)
// Check screen capture key
if (CORE.Input.Keyboard.currentKeyState[screenCaptureKey] == 1)
{
TakeScreenshot(TextFormat("screenshot%03i.png", screenshotCounter));
screenshotCounter++;
@ -6327,8 +6342,8 @@ static void PollKeyboardEvents(void)
}
#if defined(SUPPORT_SCREEN_CAPTURE)
// Check screen capture key (raylib key: KEY_F12)
if (CORE.Input.Keyboard.currentKeyState[301] == 1)
// Check screen capture key
if (CORE.Input.Keyboard.currentKeyState[screenCaptureKey] == 1)
{
TakeScreenshot(TextFormat("screenshot%03i.png", screenshotCounter));
screenshotCounter++;