summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2011-07-21 16:07:17 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2012-02-29 17:00:33 +1000
commit51da0c9f5f3ce1c010488c7a2844c28d793fbbab (patch)
treeb00484e5ea4bb4405f13a6c7e950d5b6f43e897e /tools
parent5f454a13394efa9b824230dce61c6e6e4509a5a8 (diff)
Add evemu-event to play a single event from the commandline.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'tools')
-rw-r--r--tools/Makefile.am3
-rw-r--r--tools/evemu-device.txt9
-rw-r--r--tools/evemu-event.c70
3 files changed, 79 insertions, 3 deletions
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;
+}