BUTTON_DPAD not handled by ODK?

Hi, 
I'm having trouble using the BUTTON_DPAD keys.

In my activity I have the following setup:

public boolean onKeyDown(int keyCode, KeyEvent event)  {
   boolean handled = OuyaController.onKeyDown(keyCode, event);
   return handled || super.onKeyDown(keyCode, event);
}

On the Controller side I want to check if the user pressed the DPADF or one of the analoge sticks:

if(c.getButton(OuyaController.BUTTON_DPAD_DOWN) || fYAchsis > 0.5f)
{
                     ...
                }

It seems the event is not handled by the ODK. When I step through the onKeyDown method, the boolean "handled" returns false. All other buttons except the DPAD return true.
Any Idea how I can handle this different?

Thanks,
Markus

Comments

  • batylbatyl Posts: 8Member
    I'm having this problem too. Hopefully there will be an ODK update to address it.
  • MaescoolMaescool Posts: 9Member
    I also notice that DPAD keys aren't always registering.. also with the provided ControllerTestActivity
  • hypercanestudioshypercanestudios Posts: 126Member
    Looks like they didn't add the dpad constants to their AVAILABLE_BUTTONS array.  You'l have to detect them manually in onKeyDown by looking at the keyCode rather than going through OuyaController.

  • tsmastertsmaster Posts: 7Member
    In the OUYA Controller Test sample, there's code for reading the DPAD:

            if(event.getAxisValue(MotionEvent.AXIS_HAT_X) == -1) {
                onKeyDown(OuyaController.BUTTON_DPAD_LEFT, new KeyEvent(OuyaController.BUTTON_DPAD_LEFT, KeyEvent.ACTION_DOWN));
            }

  • SquidheadSquidhead Posts: 2Member
    Thx for your reply, but this example shows how to pass the event itself to another event handler. I'd like to access the events the same way I do with the other buttons whereever I want. If I can't do that it means I have to send events by myself to all subsystems in the game where input is handled. That would be redundant to the existing OuyaController.

    For now I think I'll just ignore the DPAD and hope this will be fixed some time.
  • TomSapoTomSapo Posts: 12Member
    edited January 2013
    I faced the same situation...
    Apparently some groups of buttons on the controller are receiving different treatments during it's execution than others, or behave differently
    .

    Let's say I call "getButton(int ouyaButton)" inside the main game loop, let's name it update()

    I have this:
    60 fps.
    -------------------------------------------------------------------------------------------------------

    OuyaController c ;  > Not null and properly instantiated and recognized. ;-)

    @Override

    public void update()

    {

    super.update();

    if( c.getButton(OuyaController.BUTTON_O ) ) System.out.println("PRESSING BUTTON_O");  

    if( c.getButton(OuyaController.BUTTON_L1 ) ) System.out.println("PRESSING BUTTON_L1");

    }
    -------------------------------------------------------------------------------------------------------
    GREEN = WORKING.
    RED = NOT WORKING. 

    The GREEN GROUP of inputs recognizes the commands passed through "getButton()"method instantly while they are pressed. Very smooth, very fast and constantly.
    They are:
    O, U, Y, A, L3, R3.

    Some inputs are not working softly, and apparently they behave like a keyboard input in a text box When I press and hold the button, the command executes a single time, a little break happens, and then it continues the execution but not so fast. The RED GROUP, they are:
    D-Pad up down left right, L1, L2, R1, R2.

    This problem causes the update() method unable to recognize the inputs coming from the Red Group.

    I could see that this also happens in the example "Ouya Controller Test", especially if you have more than one controller paired. The Green group goes OK, but not the Red group: notice how the d-pad is flashing, unlike OUYA buttons that simply stay lit when pressed.

    One possible solution would be to create your own boolean flags for each of the buttons and set their values ​​inside the method keyDown (keyCode) and keyup (keyCode) like:

    public boolean Button_LEFT;
    public boolean Button_RIGHT;
    public void handleKeyDown (keycode)
    {
    if (keycode == OuyaControllers.BUTTON_DPAD_LEFT) Button_LEFT = true;
    if (keycode == OuyaControllers.BUTTON_DPAD_RIGHT) Button_RIGHT = true;
    }
    public void handleKeyUP (keycode)
    {
    if (keycode == OuyaControllers.BUTTON_DPAD_LEFT) Button_LEFT = false;
    if (keycode == OuyaControllers.BUTTON_DPAD_RIGHT) Button_RIGHT = false;
    }

    I was going that route, but then a guy (agamerguy) showed me a more elegant code, in this case used with flixel - android framework, but the same aproach appears: "boolean flags."

    http://forums.ouya.tv/discussion/comment/5706#Comment_5706

    I'd love to use the methods "controller. GetButton ()" inside the updates (), but at the moment I do not know if I'm doing something wrong or if this really could be a good update on the next version of ODK. I just do not understand why the buttons behave differently from each other.

    They also could include justPressed(keycode) and justReleased(keycode) methods.







    Post edited by TomSapo on
  • goodhustlegoodhustle Posts: 144Member
    This is a known ODK bug, which they've said will be fixed in the next version. See http://forums.ouya.tv/discussion/404/controller-buttons-only-readable-through-onkeydown-and-onkeyup#latest
    Beast Boxing Turbo - OUYA Launch Title!
  • TomSapoTomSapo Posts: 12Member
    edited January 2013
    What a relief! 
    Post edited by TomSapo on
Sign In or Register to comment.