Initial checkin
[mouse-wiggle] / mouse-wiggle.c
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <libevdev/libevdev-uinput.h>
4
5 int main() {
6 int err = 0;
7
8 struct libevdev *dev = libevdev_new();
9 libevdev_set_name(dev, "mouse-wiggle");
10 libevdev_enable_event_type(dev, EV_REL);
11 libevdev_enable_event_code(dev, EV_REL, REL_X, NULL);
12 libevdev_enable_event_code(dev, EV_REL, REL_Y, NULL);
13 libevdev_enable_event_type(dev, EV_KEY);
14 libevdev_enable_event_code(dev, EV_KEY, BTN_LEFT, NULL);
15 libevdev_enable_event_code(dev, EV_KEY, BTN_MIDDLE, NULL);
16 libevdev_enable_event_code(dev, EV_KEY, BTN_RIGHT, NULL);
17
18 struct libevdev_uinput *uidev;
19 err = libevdev_uinput_create_from_device(
20 dev,
21 LIBEVDEV_UINPUT_OPEN_MANAGED,
22 &uidev
23 );
24 if (err != 0) goto err;
25
26 sleep(1);
27
28 err = libevdev_uinput_write_event(uidev, EV_REL, REL_X, 1);
29 if (err != 0) goto err;
30 libevdev_uinput_write_event(uidev, EV_SYN, SYN_REPORT, 0);
31 if (err != 0) goto err;
32
33 sleep(1);
34
35 err = libevdev_uinput_write_event(uidev, EV_REL, REL_X, -1);
36 if (err != 0) goto err;
37 libevdev_uinput_write_event(uidev, EV_SYN, SYN_REPORT, 0);
38 if (err != 0) goto err;
39
40 err:
41 if (err != 0) {
42 fprintf(stderr, "uinput error!\n");
43 return err;
44 }
45 libevdev_uinput_destroy(uidev);
46 return 0;
47 }