Я пытаюсь генерировать нажатия клавиш и записывать их в ядро в Linux с помощью библиотеки ввода. Я нашел пример формы http://rico-studio.com/linux/read-and-write-to-a-keyboard-device/ и сделал небольшую тестовую программу. Он должен просто напечатать кучу t, но это делает только тогда, когда я нажимаю клавишу (например, место).Не удается создать нажатие клавиши, написанное на ядре устройства, с input.h Linux
#include <linux/input.h>
#include <linux/uinput.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#define EV_PRESSED 1
#define EV_RELEASED 0
#define EV_REPEAT 2
int main() {
int fd = 0;
/*In my case event3 handles the keyboard. This can be checked typing
* cat /proc/bus/input/devices in the terminal
*/
char *device = "/dev/input/event3";
struct input_event event;
memset(&event, 0, sizeof(event));
gettimeofday(&event.time, NULL);
if((fd = open(device, O_RDWR | O_NONBLOCK)) < 0)
{
printf("not opened "); // Read or Write to device
return 0;
}
for(int i=0;i <500 ;i++)
{
// usleep(1000);
event.type = EV_KEY;
// Press the key down
event.value = EV_PRESSED;
event.code = KEY_T;
write(fd, &event, sizeof(struct input_event));
// usleep(1000);
// Release the key
event.value = EV_RELEASED;
event.code = KEY_T;
write(fd, &event, sizeof(struct input_event));
usleep(100000);
}
close(fd);
return 0;
}
Может быть, этот ключ-тактный очищает память вместе с сгенерированных нажатий клавиш для т, записанных в память устройства? Поэтому мне интересно, чего мне не хватает, чтобы он генерировал нажатие клавиши и записывал ее в ядро самостоятельно.
Да. Это сделал трюк. Благодаря :) – user3379159