InputEvent Action Name Matching With InputMap

I’ve revisited the contents of my latest reply, it is still possible, but it’s a convoluted and hacky solution. I’ve created a dictionary with the event key as the key and InputMap name as the value.

Implementation below:

# - InputMapHelper.gd
func _populatePlayerActions():
	for action in InputMap.get_actions():
		if action.begins_with("Player_Ability_") or action.begins_with("Player_Item_"):
			_playerActions.get_or_add(InputMap.action_get_events(action)[0].as_text(), action)

func isPlayerItem(event: InputEvent) -> bool:
	return _playerActions.get(event.as_text() + " (Physical)").begins_with("Player_Item_")

func getEventIndex(event: InputEvent) -> int:
	return _playerActions.get(event.as_text() + " (Physical)").split("_")[2].to_int()

# - InputMapper.gd
func _input(event: InputEvent) -> void:
	if InputMapConvenience.isPlayerItem(event):
		player_item_event.emit(InputMapConvenience.getEventIndex(event))

I still don’t like this solution much. We need to add " (Physical)" to the event.as_text() because for some reason when you receive the inputEvent from the InputMap, it specifies that this event is in response to a physical key press. Magical strings are a big no no for me, so this solution is terrible to me. Furthermore, the specification for (Physical) is concerning because I don’t know what this means for software keyboards or other methods of inputs.

I still hope for a solution that is closer to my initial desires if anyone could take a crack at it, it would be appreciated. Thanks!

Edit: For the dictionary keys, I changed the key to be stored as InputMap.action_get_events(action)[0].as_text().split(" ")[0] so that we could remove the (Physical) specification. I still think it looks bad though.