9

I am developing an Android application where I would like to move the "mouse" pointer/cursor on an Android tablet. I know this is possible because when I connect a mouse (USB or BT) to an Android tablet (Honeycomb+), a cursor appears and I can interact with the tablet using the mouse only. I would like to control that mouse from Java on the Tablet.

I already have a second device that can communicate the tablet and which can stream pointer coordinates to it.

And no I can't use bluetooth. The second device that I'm using has WiFi but no ability to drive BlueTooth. My thought is that there must be a way to move the mouse pointer.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Hephaestus
  • 4,337
  • 5
  • 35
  • 48

3 Answers3

8

It is possible to control the mouse pointer in Android programmatically via the AccessibilityService API.

Here is an example app in the play store: EVA Facial Mouse app

Here is a github repository for controlling the mouse pointer via WiFi (API level 21): chetbox/android-mouse-cursor

I have forked and updated the latter repo to API level 27: Ra-Na/android-mouse-cursor

Rainer Glüge
  • 1,851
  • 1
  • 15
  • 15
  • It looks like it is not "control the mouse pointer", it is example of how you can simulate a moouse on Android – Puzirki Nov 09 '22 at 12:35
7

I would like to control that mouse from Java on the Tablet.

This is not possible, except via firmware or specialized instrumentation code. Ordinary SDK applications cannot inject input events this way.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thank you for your answer. I'm new here, so I hope this is correct place to respond. How about through the NDK? – Hephaestus Oct 08 '11 at 08:19
  • @Kevin: No, sorry. What you are describing would be a security hole, allowing one application to control another. – CommonsWare Oct 08 '11 at 08:27
  • What about trapping the mouse at a certain position? Like FPS games do when they need relative mouse motion, without hitting the screen borders. Is it possible to use an Android mouse device as an endless controller much like a trackball? – Bram Feb 12 '13 at 03:17
  • I think it is possible, look at this app: https://play.google.com/store/apps/details?id=com.crea_si.eviacam.service&hl=en_US – Rainer Glüge Feb 24 '19 at 22:14
  • @RainerGlüge: Considering that this question and answer are 7.5 years old, that is entirely possible. Lots of things have changed in Android since then. That app appears to be using the accessibility APIs, which were created for this sort of scenario and were introduced well after October 2011. – CommonsWare Feb 24 '19 at 22:17
  • I am aware of that. Unfortunately, there is not much current information available. The answer might get updated. – Rainer Glüge Feb 24 '19 at 22:45
  • @RainerGlüge: I do not know nearly enough about the accessibility APIs to explain how one would accomplish what that app does or what this question calls for. – CommonsWare Feb 24 '19 at 22:52
0

I think we can control the cursor moving now by adding an overlay view and capture the cursor motion events, hide them.

Draw own pointer. Pass the touch events to the underlying view.

Show pointer in the position of your choice and then move it relative to the original cursor

Handle captured pointer events - Documentation reference

Qamar
  • 4,959
  • 1
  • 30
  • 49