From 9b6297c917290cb45508eaaa7dc6305034d67546 Mon Sep 17 00:00:00 2001 From: Lluciocc <114759545+Lluciocc@users.noreply.github.com> Date: Fri, 17 Apr 2026 01:02:07 +0200 Subject: [PATCH 1/4] Add input.h --- src/userland/libc/input.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/userland/libc/input.h diff --git a/src/userland/libc/input.h b/src/userland/libc/input.h new file mode 100644 index 0000000..3bd9c97 --- /dev/null +++ b/src/userland/libc/input.h @@ -0,0 +1,18 @@ +#ifndef INPUT_H +#define INPUT_H + +// Arrow keys +#define KEY_UP 17 +#define KEY_DOWN 18 +#define KEY_LEFT 19 +#define KEY_RIGHT 20 + +// controls +#define KEY_ENTER 10 +#define KEY_BACKSPACE 8 +#define KEY_ESCAPE 27 +#define KEY_SPACE 32 +#define KEY_ALT 22 +#define KEY_CTRL_L 21 +#define KEY_TAB 9 + From d677d37b1cecd32ffbea5cca2b64cdc023b2a2a7 Mon Sep 17 00:00:00 2001 From: Lluciocc <114759545+Lluciocc@users.noreply.github.com> Date: Fri, 17 Apr 2026 01:05:18 +0200 Subject: [PATCH 2/4] Add keylog.c --- src/userland/gui/keylog.c | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/userland/gui/keylog.c diff --git a/src/userland/gui/keylog.c b/src/userland/gui/keylog.c new file mode 100644 index 0000000..a5f5422 --- /dev/null +++ b/src/userland/gui/keylog.c @@ -0,0 +1,62 @@ +#include "libc/syscall.h" +#include "libc/libui.h" +#include "libc/stdlib.h" +#include +#include + +/* +@Lluciocc +The most SIMPLE keylogger for debug +FEAT: +- Log every key pressed in the terminal and gives their keycode +*/ + +#define WINDOW_W 400 +#define WINDOW_H 200 + +static int last_key = -1; + +static void draw(ui_window_t win) { + ui_draw_rect(win, 0, 0, WINDOW_W, WINDOW_H, 0xFF121212); + + ui_draw_string(win, 20, 20, "Key Logger", 0xFFFFFFFF); + + if (last_key >= 0) { + char buf[32]; + itoa(last_key, buf); + + ui_draw_string(win, 20, 60, "Last key:", 0xFFAAAAAA); + ui_draw_string(win, 20, 90, buf, 0xFF6EA8FE); + } else { + ui_draw_string(win, 20, 60, "Press any key...", 0xFFAAAAAA); + } +} + +int main(void) { + ui_window_t win = ui_window_create("keylog", 100, 100, WINDOW_W, WINDOW_H); + if (!win) return 1; + + gui_event_t ev; + + while (1) { + if (ui_get_event(win, &ev)) { + + if (ev.type == GUI_EVENT_KEY) { + last_key = ev.arg1; + + printf("Key pressed: %d\n", ev.arg1); + } + + if (ev.type == GUI_EVENT_CLOSE) { + sys_exit(0); + } + + draw(win); + ui_mark_dirty(win, 0, 0, WINDOW_W, WINDOW_H); + } else { + sys_yield(); + } + } + + return 0; +} From 40f63097e1c61ef12cbc7f169f22243ef7a3ee40 Mon Sep 17 00:00:00 2001 From: Lluciocc <114759545+Lluciocc@users.noreply.github.com> Date: Fri, 17 Apr 2026 01:12:20 +0200 Subject: [PATCH 3/4] Fix missing newline at end of input.h --- src/userland/libc/input.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/userland/libc/input.h b/src/userland/libc/input.h index 3bd9c97..e5c05b6 100644 --- a/src/userland/libc/input.h +++ b/src/userland/libc/input.h @@ -16,3 +16,4 @@ #define KEY_CTRL_L 21 #define KEY_TAB 9 +#endif From e05ff65f9204824ff8704880914b27ac21b91703 Mon Sep 17 00:00:00 2001 From: Lluciocc <114759545+Lluciocc@users.noreply.github.com> Date: Fri, 17 Apr 2026 01:16:57 +0200 Subject: [PATCH 4/4] Update 2048.c with new input ref --- src/userland/games/2048.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/userland/games/2048.c b/src/userland/games/2048.c index 3700d25..2b032a5 100644 --- a/src/userland/games/2048.c +++ b/src/userland/games/2048.c @@ -1,6 +1,7 @@ #include "libc/syscall.h" #include "libc/libui.h" #include "libc/stdlib.h" +#include "libc/input.h" #include #include #include @@ -412,31 +413,20 @@ static bool point_in_rect(int px, int py, int x, int y, int w, int h) { return px >= x && px < x + w && py >= y && py < y + h; } -/* -37 = left arrow -38 = up arrow -39 = right arrow -40 = down arrow -72 = numpad 8 -75 = numpad 4 -77 = numpad 6 -80 = numpad 2 -key = letter -*/ static bool is_left_key(int key) { - return key == 'a' || key == 'A' || key == 37 || key == 75; + return key == 'a' || key == 'A' || key == KEY_LEFT; } static bool is_right_key(int key) { - return key == 'd' || key == 'D' || key == 39 || key == 77; + return key == 'd' || key == 'D' || key == KEY_RIGHT; } static bool is_up_key(int key) { - return key == 'w' || key == 'W' || key == 38 || key == 72; + return key == 'w' || key == 'W' || key == KEY_UP; } static bool is_down_key(int key) { - return key == 's' || key == 'S' || key == 40 || key == 80; + return key == 's' || key == 'S' || key == KEY_DOWN; } static void handle_click(int x, int y) {