#include <stdint.h>
#include <stdio.h>
#include <X11/keysymdef.h>
#include <X11/Xlib.h>
#include <X11/extensions/XTest.h>
struct TEvent {
uint32_t Dunno;
uint32_t Key;
uint64_t Dunno2;
};
int main()
{
char static_assert[sizeof(TEvent) == 16 ? 1 : -1];
(void)static_assert;
FILE* pf = fopen("/dev/input/js0", "r");
TEvent data;
size_t read;
Display* display = XOpenDisplay(NULL);
KeyCode keycode;
KeySym keysym;
while (true)
{
read = fread(&data, 1, 16, pf);
if (read == 16) {
switch (data.Key) {
case 163841:
keysym = XK_KP_Left;
break;
case 16941057:
keysym = XK_KP_Up;
break;
case 163839:
keysym = XK_KP_Right;
break;
case 16941055:
keysym = XK_KP_Down;
break;
case 134283265:
keysym = XK_KP_Tab;
break;
case 151060481:
keysym = XK_KP_Enter;
break;
case 65537:
keysym = XK_KP_F1;
break;
case 16842753:
keysym = XK_KP_F2;
break;
case 33619969:
keysym = XK_KP_F3;
break;
case 50397185:
keysym = XK_KP_F4;
break;
case 100728833:
keysym = XK_KP_Page_Up;
break;
case 67174401:
keysym = XK_KP_Page_Down;
break;
case 117506049:
keysym = XK_KP_Begin;
break;
case 83951617:
keysym = XK_KP_End;
break;
}
keycode = XKeysymToKeycode(display, keysym);
XTestFakeKeyEvent(display, keycode, True, 0);
XTestFakeKeyEvent(display, keycode, False, 0);
}
}
}
I2luY2x1ZGUgPHN0ZGludC5oPgojaW5jbHVkZSA8c3RkaW8uaD4KCiNpbmNsdWRlIDxYMTEva2V5c3ltZGVmLmg+CiNpbmNsdWRlIDxYMTEvWGxpYi5oPgojaW5jbHVkZSA8WDExL2V4dGVuc2lvbnMvWFRlc3QuaD4KCnN0cnVjdCBURXZlbnQgewogICAgdWludDMyX3QgRHVubm87CiAgICB1aW50MzJfdCBLZXk7CiAgICB1aW50NjRfdCBEdW5ubzI7Cn07CgppbnQgbWFpbigpCnsKICAgIGNoYXIgc3RhdGljX2Fzc2VydFtzaXplb2YoVEV2ZW50KSA9PSAxNiA/IDEgOiAtMV07CiAgICAodm9pZClzdGF0aWNfYXNzZXJ0OwogICAgRklMRSogcGYgPSBmb3BlbigiL2Rldi9pbnB1dC9qczAiLCAiciIpOwogICAgVEV2ZW50IGRhdGE7CiAgICBzaXplX3QgcmVhZDsKICAgIERpc3BsYXkqIGRpc3BsYXkgPSBYT3BlbkRpc3BsYXkoTlVMTCk7CiAgICBLZXlDb2RlIGtleWNvZGU7CiAgICBLZXlTeW0ga2V5c3ltOwogICAgd2hpbGUgKHRydWUpCiAgICB7CiAgICAgICAgcmVhZCA9IGZyZWFkKCZkYXRhLCAxLCAxNiwgcGYpOwogICAgICAgIGlmIChyZWFkID09IDE2KSB7CiAgICAgICAgICAgIHN3aXRjaCAoZGF0YS5LZXkpIHsKICAgICAgICAgICAgY2FzZSAxNjM4NDE6CiAgICAgICAgICAgICAgICBrZXlzeW0gPSBYS19LUF9MZWZ0OwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMTY5NDEwNTc6CiAgICAgICAgICAgICAgICBrZXlzeW0gPSBYS19LUF9VcDsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDE2MzgzOToKICAgICAgICAgICAgICAgIGtleXN5bSA9IFhLX0tQX1JpZ2h0OwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMTY5NDEwNTU6CiAgICAgICAgICAgICAgICBrZXlzeW0gPSBYS19LUF9Eb3duOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMTM0MjgzMjY1OgogICAgICAgICAgICAgICAga2V5c3ltID0gWEtfS1BfVGFiOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMTUxMDYwNDgxOgogICAgICAgICAgICAgICAga2V5c3ltID0gWEtfS1BfRW50ZXI7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgY2FzZSA2NTUzNzoKICAgICAgICAgICAgICAgIGtleXN5bSA9IFhLX0tQX0YxOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMTY4NDI3NTM6CiAgICAgICAgICAgICAgICBrZXlzeW0gPSBYS19LUF9GMjsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDMzNjE5OTY5OgogICAgICAgICAgICAgICAga2V5c3ltID0gWEtfS1BfRjM7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgY2FzZSA1MDM5NzE4NToKICAgICAgICAgICAgICAgIGtleXN5bSA9IFhLX0tQX0Y0OwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMTAwNzI4ODMzOgogICAgICAgICAgICAgICAga2V5c3ltID0gWEtfS1BfUGFnZV9VcDsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDY3MTc0NDAxOgogICAgICAgICAgICAgICAga2V5c3ltID0gWEtfS1BfUGFnZV9Eb3duOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMTE3NTA2MDQ5OgogICAgICAgICAgICAgICAga2V5c3ltID0gWEtfS1BfQmVnaW47CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgY2FzZSA4Mzk1MTYxNzoKICAgICAgICAgICAgICAgIGtleXN5bSA9IFhLX0tQX0VuZDsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGtleWNvZGUgPSBYS2V5c3ltVG9LZXljb2RlKGRpc3BsYXksIGtleXN5bSk7CiAgICAgICAgICAgIFhUZXN0RmFrZUtleUV2ZW50KGRpc3BsYXksIGtleWNvZGUsIFRydWUsIDApOwogICAgICAgICAgICBYVGVzdEZha2VLZXlFdmVudChkaXNwbGF5LCBrZXljb2RlLCBGYWxzZSwgMCk7CiAgICAgICAgfQogICAgfQp9Cgo=