The lack of support for named constants is not a regression relative
to the toolbox implementation.
---
 toys/android/sendevent.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 toys/android/sendevent.c
From 3fe868e66a5c1fdc3aab162604a9ff3469bdfcee Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Wed, 13 Jul 2016 17:00:58 -0700
Subject: [PATCH] Add Android's "sendevent".

The lack of support for named constants is not a regression relative
to the toolbox implementation.
---
 toys/android/sendevent.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 toys/android/sendevent.c

diff --git a/toys/android/sendevent.c b/toys/android/sendevent.c
new file mode 100644
index 0000000..8e982e0
--- /dev/null
+++ b/toys/android/sendevent.c
@@ -0,0 +1,37 @@
+/* sendevent.c - Send Linux input events.
+ *
+ * Copyright 2016 The Android Open Source Project
+
+USE_SENDEVENT(NEWTOY(sendevent, "<4>4", TOYFLAG_USR|TOYFLAG_SBIN))
+
+config SENDEVENT
+  bool "sendevent"
+  default y
+  depends on TOYBOX_ON_ANDROID
+  help
+    usage: sendevent DEVICE TYPE CODE VALUE
+
+    Sends a Linux input event.
+*/
+
+#define FOR_sendevent
+#include "toys.h"
+
+#include <linux/input.h>
+
+void sendevent_main(void)
+{
+  int fd = xopen(*toys.optargs, O_RDWR);
+  int version;
+  struct input_event ev;
+
+  if (ioctl(fd, EVIOCGVERSION, &version))
+    perror_exit("EVIOCGVERSION failed for %s", *toys.optargs);
+  
+  memset(&ev, 0, sizeof(ev));
+  // TODO: error checking and support for named constants.
+  ev.type = atoi(toys.optargs[1]);
+  ev.code = atoi(toys.optargs[2]);
+  ev.value = atoi(toys.optargs[3]);
+  xwrite(fd, &ev, sizeof(ev));
+}
-- 
2.8.0.rc3.226.g39d4020

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to