Advertisement
j0h

virtualKeyBoard

j0h
Jul 8th, 2023
1,114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.83 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){
  8.      //A hold D*3 L K J* 2 K L relese A
  9.     // Create the virtual input device
  10.     struct uinput_user_dev uidev;
  11.     memset(&uidev, 0, sizeof(uidev));
  12.     strncpy(uidev.name, "Virtual Keyboard", UINPUT_MAX_NAME_SIZE);
  13.     uidev.id.bustype = BUS_VIRTUAL;
  14.     uidev.id.vendor = 0x1234;
  15.     uidev.id.product = 0x5678;
  16.     uidev.id.version = 1;
  17.  
  18.     write(fd, &uidev, sizeof(uidev));
  19.     ioctl(fd, UI_DEV_CREATE);
  20.  
  21.     // Simulate pressing and releasing the 'A' key
  22.     struct input_event event;
  23.     memset(&event, 0, sizeof(event));
  24.  
  25.     event.type = EV_KEY;
  26.     event.code = KEY_A;
  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.  
  35.     usleep(200000);  // Delay in microseconds
  36.  
  37.     event.type = EV_KEY;
  38.     event.code = KEY_A;
  39.     event.value = 0;  // Releasing the key
  40.     write(fd, &event, sizeof(event));
  41.  
  42.     event.type = EV_SYN;
  43.     event.code = SYN_REPORT;
  44.     event.value = 0;
  45.     write(fd, &event, sizeof(event));
  46.      }
  47.  
  48. int main() {
  49.     sleep(5); // gimme a sec to start this sht
  50.     int fd = open("/dev/input/by-path/platform-i8042-serio-0-event-kbd", O_WRONLY | O_NONBLOCK);
  51.  
  52.     if (fd < 0) {
  53.         perror("Failed to open /dev/input/by-path/platform-i8042-serio-0-event-kbd");
  54.         return 1;
  55.     }
  56. //system("helm");
  57. //A hold D*3 L K J* 2 K L relese A
  58.   // Enable keyboard events
  59.     ioctl(fd, UI_SET_EVBIT, EV_KEY);
  60.     for (int keycode = KEY_ESC; keycode <= KEY_SLASH; keycode++) {
  61.         ioctl(fd, UI_SET_KEYBIT, keycode);
  62.     }
  63. Akey(fd);
  64.  
  65.     ioctl(fd, UI_DEV_DESTROY);
  66.     close(fd);
  67.  
  68.     return 0;
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement