fork(1) download
  1. #include <stdint.h>
  2. #include <stdio.h>
  3.  
  4. #include <X11/keysymdef.h>
  5. #include <X11/Xlib.h>
  6. #include <X11/extensions/XTest.h>
  7.  
  8. struct TEvent {
  9. uint32_t Dunno;
  10. uint32_t Key;
  11. uint64_t Dunno2;
  12. };
  13.  
  14. int main()
  15. {
  16. char static_assert[sizeof(TEvent) == 16 ? 1 : -1];
  17. (void)static_assert;
  18. FILE* pf = fopen("/dev/input/js0", "r");
  19. TEvent data;
  20. size_t read;
  21. Display* display = XOpenDisplay(NULL);
  22. KeyCode keycode;
  23. KeySym keysym;
  24. while (true)
  25. {
  26. read = fread(&data, 1, 16, pf);
  27. if (read == 16) {
  28. switch (data.Key) {
  29. case 163841:
  30. keysym = XK_KP_Left;
  31. break;
  32. case 16941057:
  33. keysym = XK_KP_Up;
  34. break;
  35. case 163839:
  36. keysym = XK_KP_Right;
  37. break;
  38. case 16941055:
  39. keysym = XK_KP_Down;
  40. break;
  41. case 134283265:
  42. keysym = XK_KP_Tab;
  43. break;
  44. case 151060481:
  45. keysym = XK_KP_Enter;
  46. break;
  47. case 65537:
  48. keysym = XK_KP_F1;
  49. break;
  50. case 16842753:
  51. keysym = XK_KP_F2;
  52. break;
  53. case 33619969:
  54. keysym = XK_KP_F3;
  55. break;
  56. case 50397185:
  57. keysym = XK_KP_F4;
  58. break;
  59. case 100728833:
  60. keysym = XK_KP_Page_Up;
  61. break;
  62. case 67174401:
  63. keysym = XK_KP_Page_Down;
  64. break;
  65. case 117506049:
  66. keysym = XK_KP_Begin;
  67. break;
  68. case 83951617:
  69. keysym = XK_KP_End;
  70. break;
  71. }
  72. keycode = XKeysymToKeycode(display, keysym);
  73. XTestFakeKeyEvent(display, keycode, True, 0);
  74. XTestFakeKeyEvent(display, keycode, False, 0);
  75. }
  76. }
  77. }
  78.  
  79.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty