Advertisement
j0h

keys

j0h
Jul 8th, 2023 (edited)
1,384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.48 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <fcntl.h>
  4. #include <unistd.h>
  5. #include <linux/uinput.h>
  6. #include <string.h>
  7.  void Akey(int fd,  struct uinput_user_dev uidev){
  8.      int dtime=200000; //in ms
  9.      //A hold D*3 L K J* 2 K L relese A
  10.  
  11.     // Simulate pressing and releasing the 'A' key
  12.     struct input_event event;
  13.     memset(&event, 0, sizeof(event));
  14.  
  15.     event.type = EV_KEY;
  16.     event.code = KEY_A;
  17.     event.value = 1;  // Pressing the key
  18.     write(fd, &event, sizeof(event));
  19.  
  20.     event.type = EV_SYN;
  21.     event.code = SYN_REPORT;
  22.     event.value = 0;
  23.     write(fd, &event, sizeof(event));
  24. /////////////D1///////////////////////
  25.     event.type = EV_KEY;
  26.     event.code = KEY_D;
  27.     event.value = 1;  // Pressing the key
  28.     write(fd, &event, sizeof(event));
  29.  
  30.     event.type = EV_SYN;
  31.     event.code = SYN_REPORT;
  32.     event.value = 0;
  33.     write(fd, &event, sizeof(event));
  34.     usleep(dtime/2);
  35.         event.type = EV_KEY;
  36.     event.code = KEY_D;
  37.     event.value = 0;  // Releasing the key
  38.     write(fd, &event, sizeof(event));
  39.  
  40.     event.type = EV_SYN;
  41.     event.code = SYN_REPORT;
  42.     event.value = 0;
  43.     write(fd, &event, sizeof(event));
  44.       usleep(dtime/2);
  45.     ///////////D1////////////////
  46.     /////////////D2///////////////////////
  47.     event.type = EV_KEY;
  48.     event.code = KEY_D;
  49.     event.value = 1;  // Pressing the key
  50.     write(fd, &event, sizeof(event));
  51.  
  52.     event.type = EV_SYN;
  53.     event.code = SYN_REPORT;
  54.     event.value = 0;
  55.     write(fd, &event, sizeof(event));
  56.     usleep(dtime/2);
  57.         event.type = EV_KEY;
  58.     event.code = KEY_D;
  59.     event.value = 0;  // Releasing the key
  60.     write(fd, &event, sizeof(event));
  61.  
  62.     event.type = EV_SYN;
  63.     event.code = SYN_REPORT;
  64.     event.value = 0;
  65.     write(fd, &event, sizeof(event));
  66.       usleep(dtime/2);
  67.     ///////////D2////////////////////
  68.     /////////D3///////////////////////
  69.     event.type = EV_KEY;
  70.     event.code = KEY_D;
  71.     event.value = 1;  // Pressing the key
  72.     write(fd, &event, sizeof(event));
  73.  
  74.     event.type = EV_SYN;
  75.     event.code = SYN_REPORT;
  76.     event.value = 0;
  77.     write(fd, &event, sizeof(event));
  78.     usleep(dtime/2);
  79.         event.type = EV_KEY;
  80.     event.code = KEY_D;
  81.     event.value = 0;  // Releasing the key
  82.     write(fd, &event, sizeof(event));
  83.  
  84.     event.type = EV_SYN;
  85.     event.code = SYN_REPORT;
  86.     event.value = 0;
  87.     write(fd, &event, sizeof(event));
  88.       usleep(dtime/2);
  89.     ///////////D3////////////////
  90.     /////////////L///////////////////////
  91.     event.type = EV_KEY;
  92.     event.code = KEY_L;
  93.     event.value = 1;  // Pressing the key
  94.     write(fd, &event, sizeof(event));
  95.  
  96.     event.type = EV_SYN;
  97.     event.code = SYN_REPORT;
  98.     event.value = 0;
  99.     write(fd, &event, sizeof(event));
  100.     usleep(dtime);
  101.         event.type = EV_KEY;
  102.     event.code = KEY_L;
  103.     event.value = 0;  // Releasing the key
  104.     write(fd, &event, sizeof(event));
  105.  
  106.     event.type = EV_SYN;
  107.     event.code = SYN_REPORT;
  108.     event.value = 0;
  109.     write(fd, &event, sizeof(event));
  110.       usleep(dtime);
  111.     ///////////L////////////////
  112.         /////////////K///////////////////////
  113.     event.type = EV_KEY;
  114.     event.code = KEY_K;
  115.     event.value = 1;  // Pressing the key
  116.     write(fd, &event, sizeof(event));
  117.  
  118.     event.type = EV_SYN;
  119.     event.code = SYN_REPORT;
  120.     event.value = 0;
  121.     write(fd, &event, sizeof(event));
  122.     usleep(dtime);
  123.         event.type = EV_KEY;
  124.     event.code = KEY_K;
  125.     event.value = 0;  // Releasing the key
  126.     write(fd, &event, sizeof(event));
  127.  
  128.     event.type = EV_SYN;
  129.     event.code = SYN_REPORT;
  130.     event.value = 0;
  131.     write(fd, &event, sizeof(event));
  132.       usleep(dtime);
  133.     ///////////K////////////////
  134.         /////////////J///////////////////////
  135.     event.type = EV_KEY;
  136.     event.code = KEY_J;
  137.     event.value = 1;  // Pressing the key
  138.     write(fd, &event, sizeof(event));
  139.  
  140.     event.type = EV_SYN;
  141.     event.code = SYN_REPORT;
  142.     event.value = 0;
  143.     write(fd, &event, sizeof(event));
  144.     usleep(dtime);
  145.         event.type = EV_KEY;
  146.     event.code = KEY_J;
  147.     event.value = 0;  // Releasing the key
  148.     write(fd, &event, sizeof(event));
  149.  
  150.     event.type = EV_SYN;
  151.     event.code = SYN_REPORT;
  152.     event.value = 0;
  153.     write(fd, &event, sizeof(event));
  154.       usleep(dtime*2);
  155.     ///////////J////////////////
  156.             /////////////J///////////////////////
  157.     event.type = EV_KEY;
  158.     event.code = KEY_J;
  159.     event.value = 1;  // Pressing the key
  160.     write(fd, &event, sizeof(event));
  161.  
  162.     event.type = EV_SYN;
  163.     event.code = SYN_REPORT;
  164.     event.value = 0;
  165.     write(fd, &event, sizeof(event));
  166.     usleep(dtime);
  167.         event.type = EV_KEY;
  168.     event.code = KEY_J;
  169.     event.value = 0;  // Releasing the key
  170.     write(fd, &event, sizeof(event));
  171.  
  172.     event.type = EV_SYN;
  173.     event.code = SYN_REPORT;
  174.     event.value = 0;
  175.     write(fd, &event, sizeof(event));
  176.       usleep(dtime*2);
  177.     ///////////J////////////////
  178.             /////////////K///////////////////////
  179.     event.type = EV_KEY;
  180.     event.code = KEY_K;
  181.     event.value = 1;  // Pressing the key
  182.     write(fd, &event, sizeof(event));
  183.  
  184.     event.type = EV_SYN;
  185.     event.code = SYN_REPORT;
  186.     event.value = 0;
  187.     write(fd, &event, sizeof(event));
  188.     usleep(dtime);
  189.         event.type = EV_KEY;
  190.     event.code = KEY_K;
  191.     event.value = 0;  // Releasing the key
  192.     write(fd, &event, sizeof(event));
  193.  
  194.     event.type = EV_SYN;
  195.     event.code = SYN_REPORT;
  196.     event.value = 0;
  197.     write(fd, &event, sizeof(event));
  198.       usleep(dtime*2);
  199.     ///////////K////////////////
  200.         /////////////L///////////////////////
  201.     event.type = EV_KEY;
  202.     event.code = KEY_L;
  203.     event.value = 1;  // Pressing the key
  204.     write(fd, &event, sizeof(event));
  205.  
  206.     event.type = EV_SYN;
  207.     event.code = SYN_REPORT;
  208.     event.value = 0;
  209.     write(fd, &event, sizeof(event));
  210.     usleep(dtime);
  211.         event.type = EV_KEY;
  212.     event.code = KEY_L;
  213.     event.value = 0;  // Releasing the key
  214.     write(fd, &event, sizeof(event));
  215.  
  216.     event.type = EV_SYN;
  217.     event.code = SYN_REPORT;
  218.     event.value = 0;
  219.     write(fd, &event, sizeof(event));
  220.       usleep(dtime);
  221.     ///////////L////////////////
  222.     usleep(200000);  // Delay in microseconds
  223.  
  224.     event.type = EV_KEY;
  225.     event.code = KEY_A;
  226.     event.value = 0;  // Releasing the key
  227.     write(fd, &event, sizeof(event));
  228.  
  229.     event.type = EV_SYN;
  230.     event.code = SYN_REPORT;
  231.     event.value = 0;
  232.     write(fd, &event, sizeof(event));
  233.      }
  234.  
  235. int main() {
  236.     sleep(5); // gimme a sec to start this sht
  237.     int fd = open("/dev/input/by-path/platform-i8042-serio-0-event-kbd", O_WRONLY | O_NONBLOCK);
  238.  
  239.     if (fd < 0) {
  240.         perror("Failed to open /dev/input/by-path/platform-i8042-serio-0-event-kbd");
  241.         return 1;
  242.     }
  243. //system("helm");
  244. //A hold D*3 L K J* 2 K L relese A
  245.     // Create the virtual input device
  246.     struct uinput_user_dev uidev;
  247.     memset(&uidev, 0, sizeof(uidev));
  248.     strncpy(uidev.name, "Virtual Keyboard", UINPUT_MAX_NAME_SIZE);
  249.     uidev.id.bustype = BUS_VIRTUAL;
  250.     uidev.id.vendor = 0x1234;
  251.     uidev.id.product = 0x5678;
  252.     uidev.id.version = 1;
  253.  
  254.     write(fd, &uidev, sizeof(uidev));
  255.     ioctl(fd, UI_DEV_CREATE);
  256.  
  257.   // Enable keyboard events
  258.     ioctl(fd, UI_SET_EVBIT, EV_KEY);
  259.     for (int keycode = KEY_ESC; keycode <= KEY_SLASH; keycode++) {
  260.         ioctl(fd, UI_SET_KEYBIT, keycode);
  261.     }
  262.  //   system("helm");
  263. Akey(fd, uidev);
  264.  
  265.     ioctl(fd, UI_DEV_DESTROY);
  266.     close(fd);
  267.  
  268.     return 0;
  269. }
  270.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement