问题
Assuming that I am using a generic mouse, is it possible to track the X and Y coordinates of the mouse pointer in android?
回答1:
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:
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.
回答3:
In my case the OnGenericMotion
solution did not work but attaching an OnHoverListener
to the main view did the trick.
来源:https://stackoverflow.com/questions/5454448/android-tracking-mouse-pointer-movement