diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2011-07-21 16:07:17 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2012-02-29 17:00:33 +1000 |
commit | 51da0c9f5f3ce1c010488c7a2844c28d793fbbab (patch) | |
tree | b00484e5ea4bb4405f13a6c7e950d5b6f43e897e | |
parent | 5f454a13394efa9b824230dce61c6e6e4509a5a8 (diff) |
Add evemu-event to play a single event from the commandline.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | include/evemu.h | 17 | ||||
-rw-r--r-- | src/evemu.c | 17 | ||||
-rw-r--r-- | tools/Makefile.am | 3 | ||||
-rw-r--r-- | tools/evemu-device.txt | 9 | ||||
-rw-r--r-- | tools/evemu-event.c | 70 |
5 files changed, 113 insertions, 3 deletions
diff --git a/include/evemu.h b/include/evemu.h index bfcd81e..75addec 100644 --- a/include/evemu.h +++ b/include/evemu.h @@ -315,6 +315,15 @@ int evemu_read(struct evemu_device *dev, FILE *fp); int evemu_write_event(FILE *fp, const struct input_event *ev); /** + * evemu_create_event() - Create a single event + * @ev: pointer to the kernel event to be filled + * @type: the event type to set + * @code: the event code to set + * @value: the event value to set + */ +int evemu_create_event(struct input_event *ev, int type, int code, int value); + +/** * evemu_read_event() - read kernel event from file * @fp: file pointer to read the event from * @ev: pointer to the kernel event to be filled @@ -357,6 +366,14 @@ int evemu_read_event_realtime(FILE *fp, struct input_event *ev, */ int evemu_record(FILE *fp, int fd, int ms); + +/** + * evemu_play_one() - play one events to kernel device + * @fd: file descriptor of kernel device to write to + * @ev: pointer to the kernel event to be played + */ +int evemu_play_one(int fd, const struct input_event *ev); + /** * evemu_play() - replay events from file to kernel device in realtime * @fp: file pointer to read the events from diff --git a/src/evemu.c b/src/evemu.c index aca7586..822e064 100644 --- a/src/evemu.c +++ b/src/evemu.c @@ -406,6 +406,16 @@ int evemu_read_event(FILE *fp, struct input_event *ev) return ret; } +int evemu_create_event(struct input_event *ev, int type, int code, int value) +{ + ev->time.tv_sec = 0; + ev->time.tv_usec = 0; + ev->type = type; + ev->code = code; + ev->value = value; + return 0; +} + int evemu_read_event_realtime(FILE *fp, struct input_event *ev, struct timeval *evtime) { @@ -430,6 +440,13 @@ int evemu_read_event_realtime(FILE *fp, struct input_event *ev, return ret; } +int evemu_play_one(int fd, const struct input_event *ev) +{ + int ret; + SYSCALL(ret = write(fd, ev, sizeof(*ev))); + return ret; +} + int evemu_play(FILE *fp, int fd) { struct input_event ev; diff --git a/tools/Makefile.am b/tools/Makefile.am index ca86c07..9a9d82f 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -5,7 +5,8 @@ bin_PROGRAMS = \ evemu-describe \ evemu-device \ evemu-record \ - evemu-play + evemu-play \ + evemu-event INCLUDES=-I$(top_srcdir)/include/ diff --git a/tools/evemu-device.txt b/tools/evemu-device.txt index 05d1d30..a31f12f 100644 --- a/tools/evemu-device.txt +++ b/tools/evemu-device.txt @@ -4,8 +4,8 @@ EVEMU-DEVICE(1) NAME ---- - evemu-device, evemu-play - create a virtual input device and replay an - event sequence + evemu-device, evemu-play, evemu-event - create a virtual input device + and replay an event sequence SYNOPSIS -------- @@ -13,6 +13,8 @@ SYNOPSIS evemu-play /dev/input/eventX < event-sequence + evemu-event [--sync] /dev/input/eventX type code value + DESCRIPTION ----------- evemu-device creates a virtual input device based on the description-file. @@ -24,6 +26,9 @@ stdout. evemu-play replays the event sequence given on stdin through the input device. The event sequence must be in the form created by evemu-record(1). +evemu-event plays exactly one event with the current time. If *--sync* is +given, evemu-event generates an *EV_SYN* event after the event. + evemu-device must be able to write to the uinput device node, and evemu-play must be able to write to the device node specified; in most cases this means it must be run as root. diff --git a/tools/evemu-event.c b/tools/evemu-event.c new file mode 100644 index 0000000..d599661 --- /dev/null +++ b/tools/evemu-event.c @@ -0,0 +1,70 @@ +/***************************************************************************** + * + * evemu - Kernel device emulation + * + * Copyright (C) 2011 Red Hat, Inc. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + * + ****************************************************************************/ + +#include "evemu.h" +#include <stdio.h> +#include <fcntl.h> +#include <string.h> +#include <unistd.h> +#include <stdlib.h> + +int main(int argc, char *argv[]) +{ + int fd; + long int type, code, value; + struct input_event ev; + int idx = 1; + int sync = 0; + + if (argc < 5) { + fprintf(stderr, "Usage: %s [--sync] <device> <type> <code> <value>\n", argv[0]); + return -1; + } + + if (!strcmp(argv[1], "--sync")) { + idx = 2; + sync = 1; + } + + fd = open(argv[idx++], O_WRONLY); + if (fd < 0) { + fprintf(stderr, "error: could not open device\n"); + return -1; + } + + type = strtol(argv[idx++], NULL, 0); + code = strtol(argv[idx++], NULL, 0); + value = strtol(argv[idx++], NULL, 0); + + if (evemu_create_event(&ev, type, code, value)) + fprintf(stderr, "error: failed to create event\n"); + + if (evemu_play_one(fd, &ev)) + fprintf(stderr, "error: could not play event\n"); + + if (sync) { + evemu_create_event(&ev, 0, 0, 0); + evemu_play_one(fd, &ev); + } + + close(fd); + return 0; +} |