forked from tuomasjjrasanen/python-uinput
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathkeyboard.c
More file actions
55 lines (40 loc) · 1.25 KB
/
Copy pathkeyboard.c
File metadata and controls
55 lines (40 loc) · 1.25 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
#include <stdio.h>
#include <err.h>
#include <string.h>
#include <unistd.h>
#include <suinput.h>
int main(void)
{
int i;
int uinput_fd;
int keys[] = {KEY_E, KEY_H, KEY_L, KEY_O};
struct uinput_user_dev user_dev;
memset(&user_dev, 0, sizeof(struct uinput_user_dev));
strcpy(user_dev.name, "libsuinput-example-keyboard");
uinput_fd = suinput_open();
if (uinput_fd == -1)
err(1, "suinput_open");
/* Error handling is omitted to keep code as readible as possible. */
for (i = 0; i < 4; ++i) {
suinput_enable_event(uinput_fd, EV_KEY, keys[i]);
}
suinput_create(uinput_fd, &user_dev);
sleep(1);
suinput_emit_click(uinput_fd, KEY_H);
suinput_syn(uinput_fd);
sleep(1);
suinput_emit_click(uinput_fd, KEY_E);
suinput_syn(uinput_fd);
sleep(1);
suinput_emit_click(uinput_fd, KEY_L);
suinput_syn(uinput_fd);
sleep(1);
suinput_emit_click(uinput_fd, KEY_L);
suinput_syn(uinput_fd);
sleep(1);
suinput_emit_click(uinput_fd, KEY_O);
suinput_syn(uinput_fd);
sleep(1);
suinput_destroy(uinput_fd);
return 0;
}