Android: Tracking mouse pointer movement

落花浮王杯 提交于 2019-11-30 04:42:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!