Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to fake a keyboard Up / Down press event for the Navigation in new Unity GUI system to work?

Discussion in 'UGUI & TextMesh Pro' started by BitWarp, Jan 22, 2015.

  1. BitWarp

    BitWarp

    Joined:
    Dec 24, 2014
    Posts:
    11
    I've created some buttons with the new GUI system and have set the next up and down buttons to be selectable with the "Select On Up" and "Select On Down" provided by the module in the inspector.

    They only work with the up and down arrows from the keyboard and also accept to click on the selected button by pressing space or enter.

    I'm building this menu for an Ouya game so I need the up and down events to be sent from the controller instead of a keyboard (also the enter key should be sent from another key in the controller).

    My plan is to make a script that takes the button from the Ouya controller and fakes a keyboard up / down arrow event so it makes the GUI work with the new Unity GUI system.

    something like:

    if (OuyaSDK.OuyaInput.GetButton(playerNum, OuyaController.BUTTON_DPAD_DOWN))
    {
    //Some code to fake a down arrow key pressed event so the GUI reacts to it
    }

    Can somebody tell me how to send the key press event so the GUI finally works with a controller instead of a keyboard?
     
  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,683
    Right, you don't need to "fake" the input from the controller, you just need to build your own "Ouya" InpuModule.
    If you look at the source and have a look at the StandaloneInputModule, you will see how the Up/Down keys are used.
    Then create your own input module using your input settings and then attach it to the EventSystem in your scene.
     
  3. BitWarp

    BitWarp

    Joined:
    Dec 24, 2014
    Posts:
    11
    How can I see the source of the Standalone Input Module ? (edit script doesn't open the source file from these default generated scripts)
     
  4. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,683
    Nyaow and BitWarp like this.