-
Notifications
You must be signed in to change notification settings - Fork 0
/
lrctrl.c
57 lines (44 loc) · 1.17 KB
/
lrctrl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#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;
char *device = "/dev/input/by-id/usb-413c_Dell_KB216_Wired_Keyboard-event-kbd";
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;
}
// Press the key down
event.type = EV_KEY;
event.value = EV_PRESSED;
event.code = KEY_LEFTCTRL;
write(fd, &event, sizeof(struct input_event));
event.type = EV_KEY;
event.value = EV_PRESSED;
event.code = KEY_RIGHTCTRL;
write(fd, &event, sizeof(struct input_event));
// Release the key
event.value = EV_RELEASED;
event.code = KEY_LEFTCTRL;
write(fd, &event, sizeof(struct input_event));
event.value = EV_RELEASED;
event.code = KEY_RIGHTCTRL;
write(fd, &event, sizeof(struct input_event));
//syn signal
event.type = EV_SYN;
event.code = SYN_REPORT;
event.value = 0;
write(fd, &event, sizeof(struct input_event));
close(fd);
return 0;
}