16

I know, I can listen input devices from /dev/input/eventx on Android/Linux. If you are superuser, you can also send events to the device through that.

I would like to send mouse events to my Android device as superuser. However, in order to do this, a mouse must be connected to the device via USB or bluetooth connection. Without it, I get error as Could not open /dev/input/event8, No such device when execute this command on adb sendevent /dev/input/event8 xxxx xxxx xxxxxxxx. In this case, the node was attempted to be created using the mknod /dev/input/event8 c 13 71 command.

The problem is solved when I connect a bluetooth or USB mouse to the device. The device is created automatically under /sys/devices/platform/tegra_uart.2/tty/ttyHS2/hci0 named hci0:11 also create input event /dev/input/event7 (major 13 minor 71). After that I can send events to that node and control Android mouse cursor. But I want to do this without connecting a mouse to the device.

Could anyone suggest how can I create a mouse input device (like when a mouse is connected) on my android device virtually?

Erdem UYSAL
  • 163
  • 1
  • 8
  • Yes, such as touchscreen but without real hardware device. I mean, virtual mouse device. – Erdem UYSAL Aug 15 '13 at 12:52
  • @ErdemUYSAL See http://lxr.free-electrons.com/source/Documentation/input/input.txt and also the code under drivers/input/mouse/. – Peter L. Aug 15 '13 at 23:49
  • @PeterL. Thank you for your advice. But my problem is still not resolved. Because there is gpm command in Linux, but there isn't in Android :S – Erdem UYSAL Aug 16 '13 at 08:08
  • do you find the solution ? I need that too – amir beygi Jan 05 '14 at 18:57
  • I'm having the exact same issue at the moment. By any chance, have you found a solution already? – Leon van Noord Mar 10 '15 at 08:59
  • 3
    So are you trying to inject touch events? Have you read this: http://www.pocketmagic.net/injecting-events-programatically-on-android/ – VERT9x Mar 12 '15 at 19:37
  • you don't have to inject on a mouse device. You can draw your own mouse cursor, and inject touch event when user clicks, it's a little complicated when handling drag or fling, but should work:) – bladefury Mar 16 '15 at 10:25

1 Answers1

13

From what i see you should create your own virtual device with your own driver , Fortunately there is an easy way to do so using uinput

There is an easy guide for getting started here , and this question can be a good guide to write your own virtual driver.

I thought this can only be done if you have access to kernel , and create your own ( i dont think modifying user rom is a good solution ) , but after reading this , it is clear that Uinput can run in user mode.

Note :

I agree with recommendition to use touch events ; as this solution is more common and makes sense , check second suggestion is this answer

Community
  • 1
  • 1
ProllyGeek
  • 15,517
  • 9
  • 53
  • 72
  • 1
    Great answer. I want to add that the device will disappear once the program terminates. I've been able to create an input device and send input events to the /dev/input/event* file. – Leon van Noord Mar 17 '15 at 12:44
  • @LeonvanNoord thanks , glad i could help , but can you please be more clear about device disappear thing ? just to help whoever seek this answer in future. – ProllyGeek Mar 17 '15 at 17:10
  • If the program described in part 1 of the [guide](http://thiemonge.org/getting-started-with-uinput) finishes running, the device disappears. It's not present anymore in /proc/bus/input/devices and the corresponding /dev/input/event* also disappears. – Leon van Noord Mar 18 '15 at 08:36