• Godot Help
  • controller input triggers additional keyboard input event

I have a keyboard and 2 xbox controllers connected to PC

the _Ready function returns 2 controllers correctly:

    public override void _Ready()
	{
        var joypads = Input.GetConnectedJoypads();
        foreach (var item in joypads)
        {
            GD.Print("connected joypad: " + item);
        }
    }

Outputs:

connected joypad: 0
connected joypad: 1

I then try to handle the inputs from all 3 devices like so in _Input method:

    public override void _Input(InputEvent input)
    {
        if (input is InputEventKey && input.IsPressed()) // keyboard
        {
            var keyboardInput = input as InputEventKey;
            GD.Print("keyboard pressed " + keyboardInput.Device + " " + keyboardInput.AsTextKeycode() + " " + keyboardInput.AsText() + " " + keyboardInput.AsTextKeyLabel());
        }
        else if (input is InputEventJoypadMotion && input.IsPressed()) // controller
        {
            var controllerInput = input as InputEventJoypadMotion;
            var joyName = Input.GetJoyName(controllerInput.Device);
            GD.Print("(1) controller pressed " + controllerInput.Device + " " + controllerInput.AsText() + " " + joyName);
        }
        else if (input is InputEventJoypadButton && input.IsPressed()) // also controller
        {
            var controllerInput = input as InputEventJoypadButton;
            var joyName = Input.GetJoyName(controllerInput.Device);
            GD.Print("(2) controller pressed " + controllerInput.Device + " " + controllerInput.AsText() + " " + joyName);
        }
    }

When keyboard button is pressed I get the correct 1-line log:

keyboard pressed 0 Right Right Right

However whether the first controller

(2) controller pressed 0 Joypad Button 0 (Bottom Action, Sony Cross, Xbox A, Nintendo B) XInput Gamepad
keyboard pressed 0 Enter Enter Enter

or the second controller buttons are pressed

(2) controller pressed 1 Joypad Button 1 (Right Action, Sony Circle, Xbox B, Nintendo A) XInput Gamepad
keyboard pressed 0 Space Space Space

I always see the event for both the controller AND the keyboard soon after! Why this this happening? I would like to see a single event when input happens, but currently whether controller button is pressed I get an additional event that belongs to a keyboard.

  • i think I have figured it out.
    Steam emulates your keyboard and mouse through controller. So when you move the right joystick it moves the mouse. A button press is a Space etc.. Essentially what happens is steam hooks onto controller actions and duplicates the key presses via the keyboard and mouse. Hence this caused duplicate events triggered in godot.

    With controller connected to PC - the solution was to open settings in Steam, then go to controller settings for Desktop then choose a "disabled" preset from personal preset list and apply it.

    No more duplicate events are triggered.

i think I have figured it out.
Steam emulates your keyboard and mouse through controller. So when you move the right joystick it moves the mouse. A button press is a Space etc.. Essentially what happens is steam hooks onto controller actions and duplicates the key presses via the keyboard and mouse. Hence this caused duplicate events triggered in godot.

With controller connected to PC - the solution was to open settings in Steam, then go to controller settings for Desktop then choose a "disabled" preset from personal preset list and apply it.

No more duplicate events are triggered.

    a year later

    dearme I have this problem today.
    I found that if you want to keep Steam's controller desktop configuration, you can add Godot to steam's library manually and launch Godot from there.
    Steam will not emulate keyboard and mouse input anymore, because Godot will be viewed as a game, not a desktop application.
    This might be helpful for anyone using steam deck's desktop mode for development