-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.c
More file actions
83 lines (76 loc) · 2.11 KB
/
Copy pathinput.c
File metadata and controls
83 lines (76 loc) · 2.11 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <stdio.h>
#include <stdlib.h>
#include <linux/input.h>
#include <unistd.h>
#include <fcntl.h>
/* /proc/bus/input/devices */
#define MOUSE_EVENT "/dev/input/event11"
#define KEYBOARD_EVENT "/dev/input/event12"
int keyboardfd;
int mousefd;
void send_keyboard_event(struct timeval time, int type, int code, int value)
{
struct input_event event;
event.time = time;
event.type = type;
event.code = code;
event.value = value;
write(keyboardfd, &event, sizeof(event));
}
/* /usr/include/linux/input* */
int main(void)
{
struct input_event event;
if ((mousefd = open(MOUSE_EVENT, O_RDWR)) < 0) {
puts("MOUSE_EVENT ERROR");
return(EXIT_FAILURE);
}
if ((keyboardfd = open(KEYBOARD_EVENT, O_RDWR)) < 0) {
puts("KEYBOARD_EVENT ERROR");
return(EXIT_FAILURE);
}
while (1) {
if (read(mousefd, &event, sizeof(event)) != sizeof(event)) {
puts("ERROR");
exit(EXIT_FAILURE);
}
switch(event.type) {
case EV_KEY:
//printf("EV_KEY code:%x, value:%x\n", event.code, event.value);
switch(event.code) {
case BTN_LEFT:
send_keyboard_event(event.time, EV_KEY, KEY_C, event.value);
send_keyboard_event(event.time, EV_SYN, SYN_REPORT, 0);
break;
}
break;
case EV_REL:
if (event.code == REL_WHEEL) {
//printf("EV_REL code:%x, value:%x\n", event.code, event.value);
switch(event.value) {
case 1:
// puts("up");
send_keyboard_event(event.time, EV_KEY, KEY_EQUAL, 1);
send_keyboard_event(event.time, EV_SYN, SYN_REPORT, 0);
send_keyboard_event(event.time, EV_KEY, KEY_EQUAL, 0);
send_keyboard_event(event.time, EV_SYN, SYN_REPORT, 0);
break;
case -1:
// puts("down");
send_keyboard_event(event.time, EV_KEY, KEY_MINUS, 1);
send_keyboard_event(event.time, EV_SYN, SYN_REPORT, 0);
send_keyboard_event(event.time, EV_KEY, KEY_MINUS, 0);
send_keyboard_event(event.time, EV_SYN, SYN_REPORT, 0);
break;
}
}
break;
case EV_ABS:
//printf("EV_ABS code:%x, value:%x\n", event.code, event.value);
break;
}
}
close(keyboardfd);
close(mousefd);
return(EXIT_SUCCESS);
}