← ziglang.inraylib-zigGitHub

keyboard testbed

★★☆☆by Ramon Santamaria (@raysan5)

There is no browser build of this example yet.

Is it the same as C?

//! raylib [core] example - keyboard testbed
//!
//! Zig-API translation of examples/core/core_keyboard_testbed.c (raylib 6.2).
//! NOTE: raylib defined keys refer to ENG-US Keyboard layout,
//! mapping to other layouts is up to the user
//! Example licensed under an unmodified zlib/libpng license.
//! Copyright (c) 2026 Ramon Santamaria (@raysan5)

const rl = @import("raylib");

const key_rec_spacing = 4; // Space in pixels between key rectangles

/// One key of the on-screen keyboard
const Key = struct {
    key: rl.KeyboardKey,
    width: i32 = 45,
};

/// One row of the on-screen keyboard
const Row = struct {
    keys: []const Key,
    y: f32, // Offset from the keyboard top
    height: f32,
};

const rows = [_]Row{
    // Keyboard line 01 - 15 keys
    // ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, IMP, CLOSE
    .{ .y = 0, .height = 30.0, .keys = &.{
        .{ .key = .escape }, .{ .key = .f1 },                        .{ .key = .f2 },    .{ .key = .f3 },
        .{ .key = .f4 },     .{ .key = .f5 },                        .{ .key = .f6 },    .{ .key = .f7 },
        .{ .key = .f8 },     .{ .key = .f9 },                        .{ .key = .f10 },   .{ .key = .f11 },
        .{ .key = .f12 },    .{ .key = .print_screen, .width = 62 }, .{ .key = .pause },
    } },
    // Keyboard line 02 - 15 keys
    // `, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, -, =, BACKSPACE, DEL
    .{ .y = 30 + key_rec_spacing, .height = 38.0, .keys = &.{
        .{ .key = .grave, .width = 25 }, .{ .key = .one },                    .{ .key = .two },
        .{ .key = .three },              .{ .key = .four },                   .{ .key = .five },
        .{ .key = .six },                .{ .key = .seven },                  .{ .key = .eight },
        .{ .key = .nine },               .{ .key = .zero },                   .{ .key = .minus },
        .{ .key = .equal },              .{ .key = .backspace, .width = 82 }, .{ .key = .delete },
    } },
    // Keyboard line 03 - 15 keys
    // TAB, Q, W, E, R, T, Y, U, I, O, P, [, ], \, INS
    .{ .y = 30 + 38 + key_rec_spacing * 2, .height = 38.0, .keys = &.{
        .{ .key = .tab, .width = 50 }, .{ .key = .q },                      .{ .key = .w },
        .{ .key = .e },                .{ .key = .r },                      .{ .key = .t },
        .{ .key = .y },                .{ .key = .u },                      .{ .key = .i },
        .{ .key = .o },                .{ .key = .p },                      .{ .key = .left_bracket },
        .{ .key = .right_bracket },    .{ .key = .backslash, .width = 57 }, .{ .key = .insert },
    } },
    // Keyboard line 04 - 14 keys
    // MAYUS, A, S, D, F, G, H, J, K, L, ;, ', ENTER, REPAG
    .{ .y = 30 + 38 * 2 + key_rec_spacing * 3, .height = 38.0, .keys = &.{
        .{ .key = .caps_lock, .width = 68 }, .{ .key = .a },         .{ .key = .s },
        .{ .key = .d },                      .{ .key = .f },         .{ .key = .g },
        .{ .key = .h },                      .{ .key = .j },         .{ .key = .k },
        .{ .key = .l },                      .{ .key = .semicolon }, .{ .key = .apostrophe },
        .{ .key = .enter, .width = 88 },     .{ .key = .page_up },
    } },
    // Keyboard line 05 - 14 keys
    // LSHIFT, Z, X, C, V, B, N, M, ,, ., /, RSHIFT, UP, AVPAG
    .{ .y = 30 + 38 * 3 + key_rec_spacing * 4, .height = 38.0, .keys = &.{
        .{ .key = .left_shift, .width = 80 }, .{ .key = .z },         .{ .key = .x },
        .{ .key = .c },                       .{ .key = .v },         .{ .key = .b },
        .{ .key = .n },                       .{ .key = .m },         .{ .key = .comma },
        .{ .key = .period },                  .{ .key = .slash },     .{ .key = .right_shift, .width = 76 },
        .{ .key = .up },                      .{ .key = .page_down },
    } },
    // Keyboard line 06 - 11 keys
    // LCTRL, WIN, LALT, SPACE, ALTGR, \, FN, RCTRL, LEFT, DOWN, RIGHT
    .{ .y = 30 + 38 * 4 + key_rec_spacing * 5, .height = 38.0, .keys = &.{
        .{ .key = .left_control, .width = 80 }, .{ .key = .left_super },
        .{ .key = .left_alt },                  .{ .key = .space, .width = 208 },
        .{ .key = .right_alt },                 .{ .key = @fromBackingInt(@intCast(162)) },
        .{ .key = .null },                      .{ .key = .right_control, .width = 60 },
        .{ .key = .left },                      .{ .key = .down },
        .{ .key = .right },
    } },
};

pub fn main() void {
    // Initialization
    const screen_width = 800;
    const screen_height = 450;

    rl.initWindow(screen_width, screen_height, "raylib [core] example - keyboard testbed");
    defer rl.closeWindow(); // Close window and OpenGL context
    rl.setExitKey(.null); // Avoid exit on KEY_ESCAPE

    const keyboard_offset: rl.Vector2 = .{ .x = 26, .y = 80 };

    rl.setTargetFPS(60);

    // Main game loop
    while (!rl.windowShouldClose()) { // Detect window close button or ESC key
        // Update
        const key = rl.getKeyPressed(); // Get pressed keycode
        if (@backingInt(key) > 0) rl.traceLog(.info, "KEYBOARD TESTBED: KEY PRESSED:    {d}", .{@backingInt(key)});

        const ch = rl.getCharPressed(); // Get pressed char for text input, using OS mapping
        if (ch > 0) rl.traceLog(.info, "KEYBOARD TESTBED: CHAR PRESSED:   {c} ({d})", .{ @as(u8, @truncate(@as(u32, @bitCast(ch)))), ch });

        // Draw
        rl.beginDrawing();
        defer rl.endDrawing();

        rl.clearBackground(.ray_white);

        rl.drawText("KEYBOARD LAYOUT: ENG-US", 26, 38, 20, .light_gray);

        for (rows) |row| {
            var rec_offset_x: i32 = 0;
            for (row.keys) |key_info| {
                guiKeyboardKey(.{
                    .x = keyboard_offset.x + @as(f32, @floatFromInt(rec_offset_x)),
                    .y = keyboard_offset.y + row.y,
                    .width = @floatFromInt(key_info.width),
                    .height = row.height,
                }, key_info.key);
                rec_offset_x += key_info.width + key_rec_spacing;
            }
        }
    }
}

/// Get keyboard keycode as text (US keyboard)
/// NOTE: Mapping for other keyboard layouts can be done here
fn getKeyText(key: rl.KeyboardKey) [:0]const u8 {
    return switch (key) {
        .apostrophe => "'", // Key: '
        .comma => ",", // Key: ,
        .minus => "-", // Key: -
        .period => ".", // Key: .
        .slash => "/", // Key: /
        .zero => "0", // Key: 0
        .one => "1", // Key: 1
        .two => "2", // Key: 2
        .three => "3", // Key: 3
        .four => "4", // Key: 4
        .five => "5", // Key: 5
        .six => "6", // Key: 6
        .seven => "7", // Key: 7
        .eight => "8", // Key: 8
        .nine => "9", // Key: 9
        .semicolon => ";", // Key: ;
        .equal => "=", // Key: =
        .a => "A", // Key: A | a
        .b => "B", // Key: B | b
        .c => "C", // Key: C | c
        .d => "D", // Key: D | d
        .e => "E", // Key: E | e
        .f => "F", // Key: F | f
        .g => "G", // Key: G | g
        .h => "H", // Key: H | h
        .i => "I", // Key: I | i
        .j => "J", // Key: J | j
        .k => "K", // Key: K | k
        .l => "L", // Key: L | l
        .m => "M", // Key: M | m
        .n => "N", // Key: N | n
        .o => "O", // Key: O | o
        .p => "P", // Key: P | p
        .q => "Q", // Key: Q | q
        .r => "R", // Key: R | r
        .s => "S", // Key: S | s
        .t => "T", // Key: T | t
        .u => "U", // Key: U | u
        .v => "V", // Key: V | v
        .w => "W", // Key: W | w
        .x => "X", // Key: X | x
        .y => "Y", // Key: Y | y
        .z => "Z", // Key: Z | z
        .left_bracket => "[", // Key: [
        .backslash => "\\", // Key: '\'
        .right_bracket => "]", // Key: ]
        .grave => "`", // Key: `
        .space => "SPACE", // Key: Space
        .escape => "ESC", // Key: Esc
        .enter => "ENTER", // Key: Enter
        .tab => "TAB", // Key: Tab
        .backspace => "BACK", // Key: Backspace
        .insert => "INS", // Key: Ins
        .delete => "DEL", // Key: Del
        .right => "RIGHT", // Key: Cursor right
        .left => "LEFT", // Key: Cursor left
        .down => "DOWN", // Key: Cursor down
        .up => "UP", // Key: Cursor up
        .page_up => "PGUP", // Key: Page up
        .page_down => "PGDOWN", // Key: Page down
        .home => "HOME", // Key: Home
        .end => "END", // Key: End
        .caps_lock => "CAPS", // Key: Caps lock
        .scroll_lock => "LOCK", // Key: Scroll down
        .num_lock => "NUMLOCK", // Key: Num lock
        .print_screen => "PRINTSCR", // Key: Print screen
        .pause => "PAUSE", // Key: Pause
        .f1 => "F1", // Key: F1
        .f2 => "F2", // Key: F2
        .f3 => "F3", // Key: F3
        .f4 => "F4", // Key: F4
        .f5 => "F5", // Key: F5
        .f6 => "F6", // Key: F6
        .f7 => "F7", // Key: F7
        .f8 => "F8", // Key: F8
        .f9 => "F9", // Key: F9
        .f10 => "F10", // Key: F10
        .f11 => "F11", // Key: F11
        .f12 => "F12", // Key: F12
        .left_shift => "LSHIFT", // Key: Shift left
        .left_control => "LCTRL", // Key: Control left
        .left_alt => "LALT", // Key: Alt left
        .left_super => "WIN", // Key: Super left
        .right_shift => "RSHIFT", // Key: Shift right
        .right_control => "RCTRL", // Key: Control right
        .right_alt => "ALTGR", // Key: Alt right
        .right_super => "RSUPER", // Key: Super right
        .kb_menu => "KBMENU", // Key: KB menu
        .kp_0 => "KP0", // Key: Keypad 0
        .kp_1 => "KP1", // Key: Keypad 1
        .kp_2 => "KP2", // Key: Keypad 2
        .kp_3 => "KP3", // Key: Keypad 3
        .kp_4 => "KP4", // Key: Keypad 4
        .kp_5 => "KP5", // Key: Keypad 5
        .kp_6 => "KP6", // Key: Keypad 6
        .kp_7 => "KP7", // Key: Keypad 7
        .kp_8 => "KP8", // Key: Keypad 8
        .kp_9 => "KP9", // Key: Keypad 9
        .kp_decimal => "KPDEC", // Key: Keypad .
        .kp_divide => "KPDIV", // Key: Keypad /
        .kp_multiply => "KPMUL", // Key: Keypad *
        .kp_subtract => "KPSUB", // Key: Keypad -
        .kp_add => "KPADD", // Key: Keypad +
        .kp_enter => "KPENTER", // Key: Keypad Enter
        .kp_equal => "KPEQU", // Key: Keypad =
        else => "",
    };
}

/// Draw keyboard key
fn guiKeyboardKey(bounds: rl.Rectangle, key: rl.KeyboardKey) void {
    if (key == .null) {
        rl.drawRectangleLinesEx(bounds, 2.0, .light_gray);
    } else {
        const color: rl.Color = if (rl.isKeyDown(key)) .maroon else .dark_gray;
        rl.drawRectangleLinesEx(bounds, 2.0, color);
        rl.drawText(getKeyText(key), @intFromFloat(bounds.x + 4), @intFromFloat(bounds.y + 4), 10, color);
    }

    if (rl.checkCollisionPointRec(rl.getMousePosition(), bounds)) {
        rl.drawRectangleRec(bounds, rl.fade(.red, 0.2));
        rl.drawRectangleLinesEx(bounds, 3.0, .red);
    }
}
/*******************************************************************************************
*
*   raylib [core] example - keyboard testbed
*
*   Example complexity rating: [★★☆☆] 2/4
*
*   NOTE: raylib defined keys refer to ENG-US Keyboard layout,
*   mapping to other layouts is up to the user
*
*   Example originally created with raylib 5.6, last time updated with raylib 5.6
*
*   Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
*   BSD-like license that allows static linking with closed source software
*
*   Copyright (c) 2026 Ramon Santamaria (@raysan5)
*
********************************************************************************************/

#include "raylib.h"

#define  KEY_REC_SPACING      4       // Space in pixels between key rectangles

//------------------------------------------------------------------------------------
// Module Functions Declaration
//------------------------------------------------------------------------------------
static const char *GetKeyText(int key);
static void GuiKeyboardKey(Rectangle bounds, int key);

//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
int main(void)
{
    // Initialization
    //--------------------------------------------------------------------------------------
    const int screenWidth = 800;
    const int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "raylib [core] example - keyboard testbed");
    SetExitKey(KEY_NULL); // Avoid exit on KEY_ESCAPE

    // Keyboard line 01
    int line01KeyWidths[15] = { 0 };
    for (int i = 0; i < 15; i++) line01KeyWidths[i] = 45;
    line01KeyWidths[13] = 62;   // PRINTSCREEN
    int line01Keys[15] = {
        KEY_ESCAPE, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5,
        KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11,
        KEY_F12, KEY_PRINT_SCREEN, KEY_PAUSE
    };

    // Keyboard line 02
    int line02KeyWidths[15] = { 0 };
    for (int i = 0; i < 15; i++) line02KeyWidths[i] = 45;
    line02KeyWidths[0] = 25;    // GRAVE
    line02KeyWidths[13] = 82;   // BACKSPACE
    int line02Keys[15] = {
        KEY_GRAVE, KEY_ONE, KEY_TWO, KEY_THREE, KEY_FOUR,
        KEY_FIVE, KEY_SIX, KEY_SEVEN, KEY_EIGHT, KEY_NINE,
        KEY_ZERO, KEY_MINUS, KEY_EQUAL, KEY_BACKSPACE, KEY_DELETE };

    // Keyboard line 03
    int line03KeyWidths[15] = { 0 };
    for (int i = 0; i < 15; i++) line03KeyWidths[i] = 45;
    line03KeyWidths[0] = 50;    // TAB
    line03KeyWidths[13] = 57;   // BACKSLASH
    int line03Keys[15] = {
        KEY_TAB, KEY_Q, KEY_W, KEY_E, KEY_R, KEY_T, KEY_Y,
        KEY_U, KEY_I, KEY_O, KEY_P, KEY_LEFT_BRACKET,
        KEY_RIGHT_BRACKET, KEY_BACKSLASH, KEY_INSERT
    };

    // Keyboard line 04
    int line04KeyWidths[14] = { 0 };
    for (int i = 0; i < 14; i++) line04KeyWidths[i] = 45;
    line04KeyWidths[0] = 68;    // CAPS
    line04KeyWidths[12] = 88;   // ENTER
    int line04Keys[14] = {
        KEY_CAPS_LOCK, KEY_A, KEY_S, KEY_D, KEY_F, KEY_G,
        KEY_H, KEY_J, KEY_K, KEY_L, KEY_SEMICOLON,
        KEY_APOSTROPHE, KEY_ENTER, KEY_PAGE_UP
    };

    // Keyboard line 05
    int line05KeyWidths[14] = { 0 };
    for (int i = 0; i < 14; i++) line05KeyWidths[i] = 45;
    line05KeyWidths[0] = 80;    // LSHIFT
    line05KeyWidths[11] = 76;   // RSHIFT
    int line05Keys[14] = {
        KEY_LEFT_SHIFT, KEY_Z, KEY_X, KEY_C, KEY_V, KEY_B,
        KEY_N, KEY_M, KEY_COMMA, KEY_PERIOD, /*KEY_MINUS*/
        KEY_SLASH, KEY_RIGHT_SHIFT, KEY_UP, KEY_PAGE_DOWN
    };

    // Keyboard line 06
    int line06KeyWidths[11] = { 0 };
    for (int i = 0; i < 11; i++) line06KeyWidths[i] = 45;
    line06KeyWidths[0] = 80;    // LCTRL
    line06KeyWidths[3] = 208;   // SPACE
    line06KeyWidths[7] = 60;    // RCTRL
    int line06Keys[11] = {
        KEY_LEFT_CONTROL, KEY_LEFT_SUPER, KEY_LEFT_ALT,
        KEY_SPACE, KEY_RIGHT_ALT, 162, KEY_NULL,
        KEY_RIGHT_CONTROL, KEY_LEFT, KEY_DOWN, KEY_RIGHT
    };

    Vector2 keyboardOffset = { 26, 80 };

    SetTargetFPS(60);
    //--------------------------------------------------------------------------------------

    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        // Update
        //----------------------------------------------------------------------------------
        int key = GetKeyPressed(); // Get pressed keycode
        if (key > 0) TraceLog(LOG_INFO, "KEYBOARD TESTBED: KEY PRESSED:    %d", key);

        int ch = GetCharPressed(); // Get pressed char for text input, using OS mapping
        if (ch > 0) TraceLog(LOG_INFO,  "KEYBOARD TESTBED: CHAR PRESSED:   %c (%d)", ch, ch);
        //----------------------------------------------------------------------------------

        // Draw
        //----------------------------------------------------------------------------------
        BeginDrawing();

            ClearBackground(RAYWHITE);

            DrawText("KEYBOARD LAYOUT: ENG-US", 26, 38, 20, LIGHTGRAY);

            // Keyboard line 01 - 15 keys
            // ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, IMP, CLOSE
            for (int i = 0, recOffsetX = 0; i < 15; i++)
            {
                GuiKeyboardKey((Rectangle){ keyboardOffset.x + recOffsetX, keyboardOffset.y, (float)line01KeyWidths[i], 30.0f }, line01Keys[i]);
                recOffsetX += line01KeyWidths[i] + KEY_REC_SPACING;
            }

            // Keyboard line 02 - 15 keys
            // `, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, -, =, BACKSPACE, DEL
            for (int i = 0, recOffsetX = 0; i < 15; i++)
            {
                GuiKeyboardKey((Rectangle){ keyboardOffset.x + recOffsetX, keyboardOffset.y + 30 + KEY_REC_SPACING, (float)line02KeyWidths[i], 38.0f }, line02Keys[i]);
                recOffsetX += line02KeyWidths[i] + KEY_REC_SPACING;
            }

            // Keyboard line 03 - 15 keys
            // TAB, Q, W, E, R, T, Y, U, I, O, P, [, ], \, INS
            for (int i = 0, recOffsetX = 0; i < 15; i++)
            {
                GuiKeyboardKey((Rectangle){ keyboardOffset.x + recOffsetX, keyboardOffset.y + 30 + 38 + KEY_REC_SPACING*2, (float)line03KeyWidths[i], 38.0f }, line03Keys[i]);
                recOffsetX += line03KeyWidths[i] + KEY_REC_SPACING;
            }

            // Keyboard line 04 - 14 keys
            // MAYUS, A, S, D, F, G, H, J, K, L, ;, ', ENTER, REPAG
            for (int i = 0, recOffsetX = 0; i < 14; i++)
            {
                GuiKeyboardKey((Rectangle){ keyboardOffset.x + recOffsetX, keyboardOffset.y + 30 + 38*2 + KEY_REC_SPACING*3, (float)line04KeyWidths[i], 38.0f }, line04Keys[i]);
                recOffsetX += line04KeyWidths[i] + KEY_REC_SPACING;
            }

            // Keyboard line 05 - 14 keys
            // LSHIFT, Z, X, C, V, B, N, M, ,, ., /, RSHIFT, UP, AVPAG
            for (int i = 0, recOffsetX = 0; i < 14; i++)
            {
                GuiKeyboardKey((Rectangle){ keyboardOffset.x + recOffsetX, keyboardOffset.y + 30 + 38*3 + KEY_REC_SPACING*4, (float)line05KeyWidths[i], 38.0f }, line05Keys[i]);
                recOffsetX += line05KeyWidths[i] + KEY_REC_SPACING;
            }

            // Keyboard line 06 - 11 keys
            // LCTRL, WIN, LALT, SPACE, ALTGR, \, FN, RCTRL, LEFT, DOWN, RIGHT
            for (int i = 0, recOffsetX = 0; i < 11; i++)
            {
                GuiKeyboardKey((Rectangle){ keyboardOffset.x + recOffsetX, keyboardOffset.y + 30 + 38*4 + KEY_REC_SPACING*5, (float)line06KeyWidths[i], 38.0f }, line06Keys[i]);
                recOffsetX += line06KeyWidths[i] + KEY_REC_SPACING;
            }

        EndDrawing();
        //----------------------------------------------------------------------------------
    }

    // De-Initialization
    //--------------------------------------------------------------------------------------
    CloseWindow();        // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    return 0;
}

//------------------------------------------------------------------------------------
// Module Functions Definition
//------------------------------------------------------------------------------------
// Get keyboard keycode as text (US keyboard)
// NOTE: Mapping for other keyboard layouts can be done here
static const char *GetKeyText(int key)
{
    switch (key)
    {
        case KEY_APOSTROPHE      : return "'";          // Key: '
        case KEY_COMMA           : return ",";          // Key: ,
        case KEY_MINUS           : return "-";          // Key: -
        case KEY_PERIOD          : return ".";          // Key: .
        case KEY_SLASH           : return "/";          // Key: /
        case KEY_ZERO            : return "0";          // Key: 0
        case KEY_ONE             : return "1";          // Key: 1
        case KEY_TWO             : return "2";          // Key: 2
        case KEY_THREE           : return "3";          // Key: 3
        case KEY_FOUR            : return "4";          // Key: 4
        case KEY_FIVE            : return "5";          // Key: 5
        case KEY_SIX             : return "6";          // Key: 6
        case KEY_SEVEN           : return "7";          // Key: 7
        case KEY_EIGHT           : return "8";          // Key: 8
        case KEY_NINE            : return "9";          // Key: 9
        case KEY_SEMICOLON       : return ";";          // Key: ;
        case KEY_EQUAL           : return "=";          // Key: =
        case KEY_A               : return "A";          // Key: A | a
        case KEY_B               : return "B";          // Key: B | b
        case KEY_C               : return "C";          // Key: C | c
        case KEY_D               : return "D";          // Key: D | d
        case KEY_E               : return "E";          // Key: E | e
        case KEY_F               : return "F";          // Key: F | f
        case KEY_G               : return "G";          // Key: G | g
        case KEY_H               : return "H";          // Key: H | h
        case KEY_I               : return "I";          // Key: I | i
        case KEY_J               : return "J";          // Key: J | j
        case KEY_K               : return "K";          // Key: K | k
        case KEY_L               : return "L";          // Key: L | l
        case KEY_M               : return "M";          // Key: M | m
        case KEY_N               : return "N";          // Key: N | n
        case KEY_O               : return "O";          // Key: O | o
        case KEY_P               : return "P";          // Key: P | p
        case KEY_Q               : return "Q";          // Key: Q | q
        case KEY_R               : return "R";          // Key: R | r
        case KEY_S               : return "S";          // Key: S | s
        case KEY_T               : return "T";          // Key: T | t
        case KEY_U               : return "U";          // Key: U | u
        case KEY_V               : return "V";          // Key: V | v
        case KEY_W               : return "W";          // Key: W | w
        case KEY_X               : return "X";          // Key: X | x
        case KEY_Y               : return "Y";          // Key: Y | y
        case KEY_Z               : return "Z";          // Key: Z | z
        case KEY_LEFT_BRACKET    : return "[";          // Key: [
        case KEY_BACKSLASH       : return "\\";         // Key: '\'
        case KEY_RIGHT_BRACKET   : return "]";          // Key: ]
        case KEY_GRAVE           : return "`";          // Key: `
        case KEY_SPACE           : return "SPACE";      // Key: Space
        case KEY_ESCAPE          : return "ESC";        // Key: Esc
        case KEY_ENTER           : return "ENTER";      // Key: Enter
        case KEY_TAB             : return "TAB";        // Key: Tab
        case KEY_BACKSPACE       : return "BACK";       // Key: Backspace
        case KEY_INSERT          : return "INS";        // Key: Ins
        case KEY_DELETE          : return "DEL";        // Key: Del
        case KEY_RIGHT           : return "RIGHT";      // Key: Cursor right
        case KEY_LEFT            : return "LEFT";       // Key: Cursor left
        case KEY_DOWN            : return "DOWN";       // Key: Cursor down
        case KEY_UP              : return "UP";         // Key: Cursor up
        case KEY_PAGE_UP         : return "PGUP";       // Key: Page up
        case KEY_PAGE_DOWN       : return "PGDOWN";     // Key: Page down
        case KEY_HOME            : return "HOME";       // Key: Home
        case KEY_END             : return "END";        // Key: End
        case KEY_CAPS_LOCK       : return "CAPS";       // Key: Caps lock
        case KEY_SCROLL_LOCK     : return "LOCK";       // Key: Scroll down
        case KEY_NUM_LOCK        : return "NUMLOCK";    // Key: Num lock
        case KEY_PRINT_SCREEN    : return "PRINTSCR";   // Key: Print screen
        case KEY_PAUSE           : return "PAUSE";      // Key: Pause
        case KEY_F1              : return "F1";         // Key: F1
        case KEY_F2              : return "F2";         // Key: F2
        case KEY_F3              : return "F3";         // Key: F3
        case KEY_F4              : return "F4";         // Key: F4
        case KEY_F5              : return "F5";         // Key: F5
        case KEY_F6              : return "F6";         // Key: F6
        case KEY_F7              : return "F7";         // Key: F7
        case KEY_F8              : return "F8";         // Key: F8
        case KEY_F9              : return "F9";         // Key: F9
        case KEY_F10             : return "F10";        // Key: F10
        case KEY_F11             : return "F11";        // Key: F11
        case KEY_F12             : return "F12";        // Key: F12
        case KEY_LEFT_SHIFT      : return "LSHIFT";     // Key: Shift left
        case KEY_LEFT_CONTROL    : return "LCTRL";      // Key: Control left
        case KEY_LEFT_ALT        : return "LALT";       // Key: Alt left
        case KEY_LEFT_SUPER      : return "WIN";        // Key: Super left
        case KEY_RIGHT_SHIFT     : return "RSHIFT";     // Key: Shift right
        case KEY_RIGHT_CONTROL   : return "RCTRL";      // Key: Control right
        case KEY_RIGHT_ALT       : return "ALTGR";      // Key: Alt right
        case KEY_RIGHT_SUPER     : return "RSUPER";     // Key: Super right
        case KEY_KB_MENU         : return "KBMENU";     // Key: KB menu
        case KEY_KP_0            : return "KP0";        // Key: Keypad 0
        case KEY_KP_1            : return "KP1";        // Key: Keypad 1
        case KEY_KP_2            : return "KP2";        // Key: Keypad 2
        case KEY_KP_3            : return "KP3";        // Key: Keypad 3
        case KEY_KP_4            : return "KP4";        // Key: Keypad 4
        case KEY_KP_5            : return "KP5";        // Key: Keypad 5
        case KEY_KP_6            : return "KP6";        // Key: Keypad 6
        case KEY_KP_7            : return "KP7";        // Key: Keypad 7
        case KEY_KP_8            : return "KP8";        // Key: Keypad 8
        case KEY_KP_9            : return "KP9";        // Key: Keypad 9
        case KEY_KP_DECIMAL      : return "KPDEC";      // Key: Keypad .
        case KEY_KP_DIVIDE       : return "KPDIV";      // Key: Keypad /
        case KEY_KP_MULTIPLY     : return "KPMUL";      // Key: Keypad *
        case KEY_KP_SUBTRACT     : return "KPSUB";      // Key: Keypad -
        case KEY_KP_ADD          : return "KPADD";      // Key: Keypad +
        case KEY_KP_ENTER        : return "KPENTER";    // Key: Keypad Enter
        case KEY_KP_EQUAL        : return "KPEQU";      // Key: Keypad =
        default: return "";
    }
}

// Draw keyboard key
static void GuiKeyboardKey(Rectangle bounds, int key)
{
    if (key == KEY_NULL) DrawRectangleLinesEx(bounds, 2.0f, LIGHTGRAY);
    else
    {
        if (IsKeyDown(key))
        {
            DrawRectangleLinesEx(bounds, 2.0f, MAROON);
            DrawText(GetKeyText(key), (int)(bounds.x + 4), (int)(bounds.y + 4), 10, MAROON);
        }
        else
        {
            DrawRectangleLinesEx(bounds, 2.0f, DARKGRAY);
            DrawText(GetKeyText(key), (int)(bounds.x + 4), (int)(bounds.y + 4), 10, DARKGRAY);
        }
    }

    if (CheckCollisionPointRec(GetMousePosition(), bounds))
    {
        DrawRectangleRec(bounds, Fade(RED, 0.2f));
        DrawRectangleLinesEx(bounds, 3.0f, RED);
    }
}

From raylib 6.2. The original on GitHub.