You can do something such as...

InputMap.AddAction("Jump");
InputMap.ActionAddEvent("Jump", (uint)KeyList.Space);

And within the overidden _input method...

if(Input.IsActionPressed("Jump")
{
//Do stuff
}

But how do you do this with InputEventMouseMotion?

  • Malzar replied to this.
  • Keyboard, joystick and mouse buttons work well in _Process, where you can check using InputMap if one button is pressed or released. To control the mouse motion, you should use _Input(InputEvent e) in this way:

        public override void _Input(InputEvent input) {
            if (input is InputEventMouseMotion motion) {
                GD.Print(motion.Position+" / "+motion.GlobalPosition);
            }
        }

    If you already have your code in _Process and don't want to mix your logic between _Process and _Input, you can do this in your _Process

    Alternatively, it's possible to ask the viewport for the mouse position:

    GetViewport().GetMousePosition();

    Malzar Okay, so until someone else has a more elegant solution, this is what I've done.

    InputMap.AddAction("Look Towards");

    And in the _Process method...

    
    if (InputMap.HasAction("Look Towards"))
    {
    	//code to be executed based on mouse cursor position on the screen.
    }
    6 days later

    Keyboard, joystick and mouse buttons work well in _Process, where you can check using InputMap if one button is pressed or released. To control the mouse motion, you should use _Input(InputEvent e) in this way:

        public override void _Input(InputEvent input) {
            if (input is InputEventMouseMotion motion) {
                GD.Print(motion.Position+" / "+motion.GlobalPosition);
            }
        }

    If you already have your code in _Process and don't want to mix your logic between _Process and _Input, you can do this in your _Process

    Alternatively, it's possible to ask the viewport for the mouse position:

    GetViewport().GetMousePosition();