mirror of
https://github.com/BoredDevNL/BoredOS.git
synced 2026-05-15 10:48:38 +00:00
Add keylog.c
This commit is contained in:
parent
9b6297c917
commit
d677d37b1c
1 changed files with 62 additions and 0 deletions
62
src/userland/gui/keylog.c
Normal file
62
src/userland/gui/keylog.c
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
#include "libc/syscall.h"
|
||||||
|
#include "libc/libui.h"
|
||||||
|
#include "libc/stdlib.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
@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;
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue