#include <stdio.h>
#include <unistd.h>
#include <linux/input.h>
#include <linux/uinput.h>
#include "fakedev.h"
int btn0_setup(struct uinput_user_dev *dev, int fd)
{
if (ioctl(fd, UI_SET_EVBIT, EV_KEY) == -1) goto error;
if (ioctl(fd, UI_SET_EVBIT, EV_REL) == -1) goto error;
if (ioctl(fd, UI_SET_EVBIT, EV_SYN) == -1) goto error;
if (ioctl(fd, UI_SET_KEYBIT, BTN_0) == -1) goto error;
if (ioctl(fd, UI_SET_KEYBIT, BTN_1) == -1) goto error;
if (ioctl(fd, UI_SET_KEYBIT, BTN_2) == -1) goto error;
if (ioctl(fd, UI_SET_RELBIT, REL_X) == -1) goto error;
if (ioctl(fd, UI_SET_RELBIT, REL_Y) == -1) goto error;
return 0;
error:
perror("ioctl failed.");
return -1;
}
int btn0_run(int fd)
{
move(fd, -10, 0);
usleep(1000);
move(fd, 0, -10);
usleep(1000);
move(fd, 10, 0);
usleep(1000);
move(fd, 0, 10);
usleep(1000);
click(fd, BTN_0, 1);
usleep(1000);
click(fd, BTN_0, 0);
return 0;
}
struct test_device btn0_dev = {
.name = "BTN_0 test device",
.setup = btn0_setup,
.run = btn0_run,
};
struct test_device* get_device()
{
return &btn0_dev;
}