Question

I'm writing a game for OUYA and Android and I'm using the trackpad on the OUYA controller. When ever you touch it a mouse pointer comes up and I can't find a way to hide it. I image this would be a problem for games on an Android netbook as well. Has anyone found a way to interact with the cursor instead of just listening for events?

No correct solution

OTHER TIPS

This won't hide the mouse, but it will at least help prevent touch events from interfering with your joystick processing code -- not a proper solution I know, but still might help people who land on this page:

public boolean onGenericMotionEvent(MotionEvent event) {
    if ( (event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
        //handle the event
        return true;
    }
    else {
        return false;
    }
}

Android currently does not expose any functionality to hide the mouse cursor. Whenever you have an external pointing device (ie. usb/bluetooth mouse, trackpad, etc) a mouse pointer will appear on the screen whenever you interact with the device.

Unfortunately (as of JB 4.2.2) this means it is impossible without a modified ROM.

It is possible to request pointer capture now. You need to explicitly request capture:

fun onClick(view: View) {
    view.requestPointerCapture()
}

As documented:

Android delivers pointer events from sources other than the mouse normally, but the mouse pointer is not visible anymore.

You can either handle pointer events by overriding onCapturedPointerEvent:

override fun onCapturedPointerEvent(motionEvent: MotionEvent): Boolean {
    // Get the coordinates required by your app
    val verticalOffset: Float = motionEvent.y
    // Use the coordinates to update your view and return true if the event was
    // successfully processed
    return true
}

or registering an event handler for OnCapturedPointerListener:

myView.setOnCapturedPointerListener { view, motionEvent ->
    // Get the coordinates required by your app
    val horizontalOffset: Float = motionEvent.x
    // Use the coordinates to update your view and return true if the event was
    // successfully processed
    true
}

And it's up to you to release the pointer when you're done:

override fun onClick(view: View) {
    view.releasePointerCapture()
}

I know that the context of this question overall may not apply (ie: Ouya development), but this was the first search result when I looked into how to do this myself. So I figured that I'd update the answer!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top