How to get the amount of movement of Bluetooth mouse connected to Android device through the app

Asked 2 years ago, Updated 2 years ago, 72 views

If you connect the mouse to the Android device, the cursor will appear on the screen and you will be able to operate it.
I am using a Bluetooth mouse paired with an Android device, and I would like to obtain the amount of movement of this mouse on the Android app.

Normally, you can get it from MotionEvent hover, but if the cursor tries to get out of the screen, the coordinates are moved into the screen without permission, so even if you do getX, the coordinates will not change.That's why I'm in trouble.
When I got it on my PC, I was foolish enough to move the cursor back to the center of the screen and get the difference between the coordinates and the center after moving the mouse every frame.

However, after a little investigation, I found that it would be difficult to move the mouse cursor itself for security reasons without using Root on Android.
It would be great if the app could get information on the amount of movement that Bluetooth is getting, but is there such a way?

Currently, I have no choice but to obtain the amount of movement on my PC and send it to my smartphone via UDP, but there is a delay of up to a few seconds.
I tried to modify the mouse to get the amount of movement, but I don't think I can solder it because I use a very small Bluetooth mouse.
I did AMOTION_getRawX() on NDK, but I just returned the coordinates of the screen...

I would like to obtain the amount of movement directly through the app.Please help me.Thank you for your cooperation.

java android bluetooth

2022-09-30 19:13

2 Answers

Self-resolved!!

Start ADB using an app called Android Terminal Emulator and issue the ADB command adb shell getevent-lt/dev/input/event5 from the app.
event5 varies by device, so check adb shell getevent-i.

You can see the REL_X and REL_Y items in the log.
This is how much the mouse moves. It keeps going even at the end of the screen.

I'll also convert the value from a hexadecimal string to Int.
intd=(int)Long.parseLong(hexValue, 16);

I don't want to use an external app if I have to, so I want to read the source and incorporate it into my own app, but now I can do what I want to do!


2022-09-30 19:13

Override onGenericMotionEvent to retrieve the MotionEvent for mouse movement (ACTION_HOVER_MOVE).
Drag and so on does not refer to onGenericMotionEvent, but onTouchEvent.


2022-09-30 19:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.