Assuming that I am using a generic mouse, is it possible to track the X and Y coordinates of the mouse pointer in android?
3 Answers 3
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.
2 Comments
View.OnGenericMotion(View v, MotionEvent event) is available starting with api level 12: http://developer.android.com/reference/android/view/View.OnGenericMotionListener.html#onGenericMotion 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.
5 Comments
In my case the OnGenericMotion solution did not work but attaching an OnHoverListener to the main view did the trick.
Comments
Explore related questions
See similar questions with these tags.