#How does InputEvent.Device work?

4 messages · Page 1 of 1 (latest)

fallow crescent
#

I'm looking to create an input system for local multiplayer where I can track individual input sources.
However, when I run a simple scene, every InputEvent has the same Device value, zero.
Here is a basic script I was using to test:

public partial class Foobar : Node3D
{
  public override void _Input(InputEvent e)
  {
    GD.Print(e.Device);
  }
}

I validated this using keyboard, mouse, & xbox controller inputs. Is this a bug or am I doing something wrong? If all IDs are the same, then IDK how to use Input.GetJoyName(deviceNumber)

fallow crescent
#

How does InputEvent.Device work?

calm forge
#

I just tested this.
I seems like only devices of the same category have different ids - so you need to make sure you don't compare the ids of different device types.

this is what I got:
Mouse: event.Device = 0
Keyboard: event.Device = 0
DS4 Controller 1: event.Device = 0
DS4 Controller 2: event.Device = 1

#

heres some example code for checking for different examples:

    if (inputEvent is InputEventJoypadButton)
        {
            GD.Print($"joystick pressed, device: {inputEvent.Device}");
        }
        if (inputEvent is InputEventMouseButton)
        {
            GD.Print($"mouse pressed,  device: {inputEvent.Device}");
        }
        if (inputEvent is InputEventKey)
        {
            GD.Print($"keyboard pressed, device id: {inputEvent.Device}");
        }```