Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate USB mouse pointer input on Android phone?

Tags:

android

mouse

Is it possible to simulate USB mouse movement and click inputs on an Android phone (or on the emulator), e.g. using USB debugging? I want to test if everything in my app also works when using a mouse, but I don't have a mouse I can connect to my Android phone.

like image 509
stefan.at.wpf Avatar asked Sep 28 '26 12:09

stefan.at.wpf


1 Answers

You can do this with ADB by sending the events you want to the device. Here if you want to send a click event from the mouse, you can do this:

adb shell input mouse tap <x> <y>

Here's the docs for adb shell input:

$ adb shell input --help
Usage: input [<source>] [-d DISPLAY_ID] <command> [<arg>...]

The sources are:
    dpad
    keyboard
    mouse
    touchpad
    gamepad
    touchnavigation
    joystick
    touchscreen
    stylus
    trackball

-d: specify the display ID.
    (Default: -1 for key event, 0 for motion event if not specified.)
The commands and default sources are:
    text <string> (Default: touchscreen)
    keyevent [--longpress] <key code number or name> ... (Default: keyboard)
    tap <x> <y> (Default: touchscreen)
    swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)
    draganddrop <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)
    press (Default: trackball)
    roll <dx> <dy> (Default: trackball)
    event <DOWN|UP|MOVE> <x> <y> (Default: touchscreen)

KeyEvent codes: https://developer.android.com/reference/android/view/KeyEvent?hl=en#constants

like image 117
Nicolas Avatar answered Oct 01 '26 05:10

Nicolas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!