Ouya controller, how to prevent pressing the a button from canceling your game when running?

So I'm testing out our game on the ouya using the ouya controller and we created a little diagram test to verify the buttons we press on the controller map to the correct key values. However, if I press the A button while in game, it causes the game to cancel and takes me back to the games screen.

How do I prevent this from happening?

@Override
public boolean onKeyDown(final int keyCode, KeyEvent event){
    //Get the player #
    int player = OuyaController.getPlayerNumByDeviceId(event.getDeviceId());       
    boolean handled = false;

    //Handle the input
    switch(keyCode){
        case OuyaController.BUTTON_O:
            //You now have the key pressed and the player # that pressed it
            //doSomethingWithKey();
            handled = true;
            break;
    }
    return handled || super.onKeyDown(keyCode, event);
}
Looking at this controller doc example code, do I need to make sure I prevent the super.onKeyDown from processing the event when the A button is pressed?

Best Answer

  • noctnoct Posts: 122Member
    Answer ✓
    You just need to handled = true the key.

Answers

  • hypercanestudioshypercanestudios Posts: 126Member
    Try calling requestFocus on your view prior to handling controller input.
  • MagnesusMagnesus Posts: 304Member
    I believe A is mapped to Android back key which is the reason it happens.

  • vinfangvinfang Posts: 8Member
    Just wanted to add a follow up along with what I learned from this and thanks to all for answering. 


    The above sample code I got from the Ouya Git docs is correct. If you want to prevent the buttons on the controller from performing default things like A for back and O for confirm, you must make sure when you override the onKeyDown in the Activity class of Android that you prevent it from calling its super.onKeyDown, otherwise the default actions will occur.
Sign In or Register to comment.