In Slate, is it possible to directly query the input state or otherwise create complex input combinations?

We’re using the Unreal ImGui plugin which is driven through Slate. We would like to be able to open the debug menu with a more complex button combo on the gamepad e.g. left thumbstick and start button. Basically, we would be using the left thumbstick (or some other button) as a modifier in the same way that you might use shift or control on the keyboard.

Is there a way to either directly query the input state of the controller to see what buttons are currently down or is there a built in way to do button combos?

virtual FReply OnKeyDown(const FGeometry &Geometry, const FKeyEvent& KeyEvent) override;
FReply SMySlateWidget::OnKeyDown(const FGeometry &Geometry, const FKeyEvent& KeyEvent)
{
    if (( KeyEvent.GetKey() == EKeys::K ) &&
    ( KeyEvent.IsCommandDown() || KeyEvent.IsControlDown() ))
    {
        // do stuff
    }
}

That’s not a directly querying the input and that’s just a simple button combo using the build in stuff that lets you check for shift/alt/etc.

Let’s take a nonsensical combo and say I wanted to trigger something when the G and P keys were pressed at the same time. How would I do that?

Yes, you can query the input state of the controller to see what buttons are currently down in Unreal Engine. You can use the GetInputKeyDown or GetInputKeyTimeDown functions of the APlayerController class to check whether a particular button is currently down.

To check if a button combination has been pressed, you can keep track of the current state of the modifier button (in this case, the left thumbstick) and the other button (in this case, the start button) in your game code. You can then check the state of both buttons in your game code to determine if the button combo has been pressed.

Here’s an simple example of a left thumbstick and start button combo:

bool bLeftThumbstickDown = false;

// check for the left thumbstick and start button combination
bool IsDebugMenuButtonComboPressed()
{
    // get the player controller
    APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();

    // check if the left thumbstick is currently down
    if (PlayerController->GetInputKeyTimeDown(EKeys::Gamepad_LeftThumbstick) > 0.f)
    {
        bLeftThumbstickDown = true;
    }
    else if (PlayerController->GetInputKeyTimeUp(EKeys::Gamepad_LeftThumbstick) > 0.f)
    {
        bLeftThumbstickDown = false;
    }

    // check if the start button is currently down and the left thumbstick was pressed before
    if (PlayerController->IsInputKeyDown(EKeys::Gamepad_Special_Right))
    {
        if (bLeftThumbstickDown)
        {
            // the button combo has been pressed
            return true;
        }
    }

    return false;
}

You can now call the IsDebugMenuButtonComboPressed function in your game code to check if the button combo has been pressed. If it returns true, you can then open the debug menu.

I hope this does the trick :eyes:

Thanks for the reply. This won’t do it either as I’m working in Slate, so no World and no PlayerController.