Repository: godot
Issue: Removing an action event with InputMap causes Input.is_action_pressed to return true in some cases
Labels: bug,needs testing,topic:input

### Godot version

v3.4.4.stable.official [419e713a2]

### System information

Windows 10

### Issue description

I'm using `InputMap` to manually manage input actions and events. 

I noticed that if I call `InputMap.action_erase_events` to remove an action, it suddenly causes `Input.is_action_pressed` to start returning `true` for that action, despite there not being any events associated with it.

In particular, this happens when `InputMap.action_erase_events` is called in response to the event being triggered.

Okay, that sounded a little complicated, so let me explain with a practical example:

Let's start off with a completely empty InputMap (I manually removed all events from the project settings). We'll do all InputMap management in code.

First, I create an action called "test". And to this action I add a keyboard event with the key "D". So, when I press "D" on the keyboard, the "test" action will fire.

I've tested this in a `_process` block by checking `Input.is_action_pressed("test")` which returns true as long as the "D" key is being held down, and false otherwise. So far so good!

Now, let's add an `_input` function to detect inputs as they come in. Inside `_input` I do a `event.is_action_pressed("test")` to also check when the "D" key is pressed. And again, this works fine.

Now, let's say I want to remove all events from the "test" action. I call `InputMap.action_erase_events("test")`. I'm doing this as a response of the user pressing "D". So what happens is "D" is pressed, and then all events for "test" are removed, so in theory from that point on, nothing should trigger the "test" action because there are no events associated with it.

But that's where the bug happens. After removing all events (including the "D" key) from the "test" action, the `Input.is_action_pressed("test")` starts return `true` inside the `_process` block. This is not expected because I would expected `Input.is_action_pressed("test")` to return false always since there's no event associated with it anymore, so in theory it should never be considered "pressed".

It seems like there's some kind of race condition or some kind of cached or stuck state internally. It definitely has something to do with the "D" key being used to trigger the `action_erase_events` call. So it could be that the key was pressed, and then while being pressed the events were removed, but that "pressed" state somehow got stuck. 

So maybe there needs to be something internally that resets the pressed state when an event is removed. Or maybe a new function we can call to force this, like `Input.action_reset_state("test")` or something.

I noticed this bug randomly while working on a game, because I have an input binding menu in my options and users can remove inputs from actions. And I noticed that when the user removes a button mapping, it suddenly starts triggering `is_action_pressed` as `true` is my `process` even though it should be false because there's no button being bound to that action anymore.

I've created a simple test project that focuses on this bug (see attached zip below).

Here's the only script that's in the project:

```gdscript
extends Node2D

const TEST_ACTION_NAME: String = "test"

onready var color_rect: ColorRect = $ColorRect

func _ready():
	var test_keyboard_event: InputEventKey = InputEventKey.new()
	test_keyboard_event.scancode = KEY_D

	InputMap.add_action(TEST_ACTION_NAME)
	InputMap.action_add_event(TEST_ACTION_NAME, test_keyboard_event)

func _process(delta: float) -> void:
	if Input.is_action_pressed(TEST_ACTION_NAME):
		color_rect.color = Color.green
	else:
		color_rect.color = Color.red

func _input(event: InputEvent) -> void:
	if event.is_action_pressed(TEST_ACTION_NAME):
		InputMap.action_erase_events(TEST_ACTION_NAME)
```

### Steps to reproduce

1. Launch the test project (zip below)
2. I've added a `ColorRect` to illustrate the state of the input action. This rect represents the state of `is_action_pressed`, and is triggered by the "D" key on the keyboard. In theory the square should only be green when the "D" key is pressed down, otherwise it should be red.
3. Press and release the "D" key on your keyboard
4. Notice that the square is stuck on green even after you let go of the key. This is because as part of pressing "D" I've also removed all events from the input action. And this is where the bug comes in. When removing the events it seems to get stuck on a "pressed" state instead of resetting itself.

**Expected behavior**: I would expect `is_action_pressed` to return `false` always if the action has no events associated with it (the square should be red in the test project).

### Minimal reproduction project

[TestInputRemoveBug.zip](https://github.com/godotengine/godot/files/9229312/TestInputRemoveBug.zip)