Android: tracking mouse pointer

Assuming I'm using a general mouse, is it possible to track the X and Y coordinates of the mouse pointer in android?

+5
source share
3 answers

You will need OnGenericMotionListener:

OnGenericMotion(...., MotionEvent me) {
if (me.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) {

}

api is 14+necessary [confirmed] The tablet I found with a usb mouse and can confirm that this works for mouse movement. You will be filled with messages, so you should consider simple operations or sleep.

+7
source

The ACTION_MOVE docs make me think that only drag and drop events will be reported:

getAction(): - ( ACTION_DOWN ACTION_UP). , .

0

In my case, the solution OnGenericMotiondid not work, but binding OnHoverListenerto the main view did the trick.

0
source

All Articles