-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstructs.c
68 lines (59 loc) · 1.66 KB
/
structs.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
58
59
60
61
62
63
64
65
66
67
68
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/input.h>
#include <linux/uinput.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
int out = open("uinput_user_dev.dump", O_WRONLY | O_CREAT, 0644);
if (out < 0)
{
perror("Unable to open output");
close(out);
return -1;
}
struct uinput_user_dev device;
memset(&device, 0, sizeof(device)); // Initialize uinput device to NULL
strncpy(device.name, "speech-input", UINPUT_MAX_NAME_SIZE);
device.id.bustype = 1;
device.id.vendor = 2;
device.id.product = 3;
device.id.version = 4;
device.ff_effects_max = 5;
device.absmax[0] = 6;
device.absmin[0] = 7;
device.absfuzz[0] = 8;
device.absflat[0] = 9;
if (write(out, &device, sizeof(device)) < sizeof(device)) {
perror("Failed to write device info to file");
close (out);
return -1;
}
close(out);
out = open("input_event.dump", O_WRONLY | O_CREAT, 0644);
if (out < 0)
{
perror("Unable to open output");
close(out);
return -1;
}
struct input_event event;
memset(&event, 0, sizeof(event)); // Clear event structure.
gettimeofday(&event.time, NULL);
event.type = EV_KEY; //indicates the keyboard event
event.code = KEY_A;
event.value = 1; //key down
if (write (out, &event, sizeof(event)) < sizeof(out)) {
perror("Failed to write device info to file");
close (out);
return -1;
}
return 0;
}