Assuming that I am using a generic mouse, is it possible to track the X and Y coordinates of the mouse pointer in android?
Android: Tracking mouse pointer movement
Asked Answered
You need a OnGenericMotionListener
:
OnGenericMotion(...., MotionEvent me) {
if (me.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) {
}
api 14+
needed
[confirmed] Found me a tablet with usb mouse and can confirm this works for mouse movement. You WILL get flooded with messages, so simple operations or sleeping should be considered.
Hmm in my case i attached it to a webview and I only get events when I click on the left mouse button... –
Merwyn
The docs to ACTION_MOVE lead me to think that only drag events would be reported:
Constant for getAction(): A change has happened during a press gesture (between ACTION_DOWN and ACTION_UP). The motion contains the most recent point, as well as any intermediate points since the last down or move event.
Thank so much for your insight Matthew. I've also read about that. I think what I need to know if there is any way to track the mouse movement without having an ACTION_DOWN MotionEvent? –
Mahla
Do you have an Android device that has a mouse? If so you could test this out. I wasn't aware that there were any with mice. –
Acetal
Yeah, I actually have an android tablet that can use a mouse through USB port. Also, I already have a method using ACTION_DOWN, ACTION_MOVE, and ACTION_DOWN and yes, they are working fine. But is there any way to have an ACTION_MOVE event for a mouse pointer without having an ACTION_DOWN first? –
Mahla
Hi. I'm facing the same problem. Save you found a way to track the mouse movements. I heard that it is possible to get the mouse movements using Internal classes, but not easy. –
Liselisetta
does any one know how to use mouse from other system i.e mouse is connected to my laptop and laptop and tablet are connected using wi-fi direct.Now i want to use mouse in tablet.. –
Galata
In my case the OnGenericMotion
solution did not work but attaching an OnHoverListener
to the main view did the trick.
© 2022 - 2024 — McMap. All rights reserved.
View.OnGenericMotion(View v, MotionEvent event)
is available starting with api level 12: http://developer.android.com/reference/android/view/View.OnGenericMotionListener.html#onGenericMotion – Kagoshima