Screenshot key

This commit is contained in:
BlueStag 2023-01-02 12:41:20 +00:00 committed by GitHub
parent 0ccc1d3686
commit 4753dca03f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -1099,6 +1099,7 @@ RLAPI bool IsKeyDown(int key); // Check if a key
RLAPI bool IsKeyReleased(int key); // Check if a key has been released once RLAPI bool IsKeyReleased(int key); // Check if a key has been released once
RLAPI bool IsKeyUp(int key); // Check if a key is NOT being pressed RLAPI bool IsKeyUp(int key); // Check if a key is NOT being pressed
RLAPI void SetExitKey(int key); // Set a custom key to exit program (default is ESC) RLAPI void SetExitKey(int key); // Set a custom key to exit program (default is ESC)
RLAPI void SetScreenshotKey(int key); // Set a custom key to take a screnshot (default is F12)
RLAPI int GetKeyPressed(void); // Get key pressed (keycode), call it multiple times for keys queued, returns 0 when the queue is empty RLAPI int GetKeyPressed(void); // Get key pressed (keycode), call it multiple times for keys queued, returns 0 when the queue is empty
RLAPI int GetCharPressed(void); // Get char pressed (unicode), call it multiple times for chars queued, returns 0 when the queue is empty RLAPI int GetCharPressed(void); // Get char pressed (unicode), call it multiple times for chars queued, returns 0 when the queue is empty

View File

@ -429,6 +429,7 @@ typedef struct CoreData {
#endif #endif
struct { struct {
int exitKey; // Default exit key int exitKey; // Default exit key
int screenshotKey; // Default screenshot key
char currentKeyState[MAX_KEYBOARD_KEYS]; // Registers current frame key state char currentKeyState[MAX_KEYBOARD_KEYS]; // Registers current frame key state
char previousKeyState[MAX_KEYBOARD_KEYS]; // Registers previous frame key state char previousKeyState[MAX_KEYBOARD_KEYS]; // Registers previous frame key state
@ -763,6 +764,7 @@ void InitWindow(int width, int height, const char *title)
// Initialize global input state // Initialize global input state
memset(&CORE.Input, 0, sizeof(CORE.Input)); memset(&CORE.Input, 0, sizeof(CORE.Input));
CORE.Input.Keyboard.exitKey = KEY_ESCAPE; CORE.Input.Keyboard.exitKey = KEY_ESCAPE;
CORE.Input.Keyboard.screenshotKey = KEY_F12;
CORE.Input.Mouse.scale = (Vector2){ 1.0f, 1.0f }; CORE.Input.Mouse.scale = (Vector2){ 1.0f, 1.0f };
CORE.Input.Mouse.cursor = MOUSE_CURSOR_ARROW; CORE.Input.Mouse.cursor = MOUSE_CURSOR_ARROW;
CORE.Input.Gamepad.lastButtonPressed = -1; CORE.Input.Gamepad.lastButtonPressed = -1;
@ -3558,6 +3560,15 @@ void SetExitKey(int key)
#endif #endif
} }
// Set a custom key to take a screenshot
// NOTE: default screenshotKey is F12
void SetScreenshotKey(int key)
{
#if !defined(PLATFORM_ANDROID)
CORE.Input.Keyboard.screenshotKey = key;
#endif
}
// NOTE: Gamepad support not implemented in emscripten GLFW3 (PLATFORM_WEB) // NOTE: Gamepad support not implemented in emscripten GLFW3 (PLATFORM_WEB)
// Check if a gamepad is available // Check if a gamepad is available
@ -5304,7 +5315,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 ((key == CORE.Input.Keyboard.exitKey) && (action == GLFW_PRESS)) glfwSetWindowShouldClose(CORE.Window.handle, GLFW_TRUE);
#if defined(SUPPORT_SCREEN_CAPTURE) #if defined(SUPPORT_SCREEN_CAPTURE)
if ((key == GLFW_KEY_F12) && (action == GLFW_PRESS)) if ((key == CORE.Input.Keyboad.screenshotKey) && (action == GLFW_PRESS))
{ {
#if defined(SUPPORT_GIF_RECORDING) #if defined(SUPPORT_GIF_RECORDING)
if (mods == GLFW_MOD_CONTROL) if (mods == GLFW_MOD_CONTROL)
@ -6428,8 +6439,7 @@ static void PollKeyboardEvents(void)
} }
#if defined(SUPPORT_SCREEN_CAPTURE) #if defined(SUPPORT_SCREEN_CAPTURE)
// Check screen capture key (raylib key: KEY_F12) if (CORE.Input.Keyboard.currentKeyState[CORE.Input.Keyboad.screenshotKey] == 1)
if (CORE.Input.Keyboard.currentKeyState[301] == 1)
{ {
TakeScreenshot(TextFormat("screenshot%03i.png", screenshotCounter)); TakeScreenshot(TextFormat("screenshot%03i.png", screenshotCounter));
screenshotCounter++; screenshotCounter++;