Skip to content

modifier actions will shadow simple actions if flag=false (fix #18793)

It will keep the current input behavior, if needed is_action_pressed_on_modifier=false can be set. (also improved as_text() for modifiers)

Test script:

extends Control

const is_action_pressed_on_modifier = 0

func _ready():
	add_key("Save", get_combo([KEY_CONTROL], KEY_S))
	add_key("Select S", get_keyboard_event(KEY_S), is_action_pressed_on_modifier)
	
	add_key("Run", get_keyboard_event(KEY_SHIFT))
	add_key("Jump", get_keyboard_event(KEY_SPACE), is_action_pressed_on_modifier)
	add_key("Super Jump", get_combo([KEY_SHIFT], KEY_SPACE))

func get_combo(modifiers, key):
	var new_event = InputEventKey.new()
	new_event.scancode = key
	
	for m in modifiers:
		if typeof(m)==TYPE_INT:
			if m==KEY_ALT:
				new_event.set_alt(true)
			if m==KEY_SHIFT:
				new_event.set_shift(true)
			if m==KEY_CONTROL:
				new_event.set_control(true)
			if m==KEY_META:
				new_event.set_meta(true)
			if m==KEY_MASK_CMD:
				new_event.set_command(true)
	
	return new_event

func get_keyboard_event(key):
	var new_event = InputEventKey.new()
	new_event.scancode = key
	return new_event

func add_key(action, key_event, _is_action_pressed_on_modifier=true):
	key_event.set_action_pressed_on_modifier(_is_action_pressed_on_modifier)
	
	if !InputMap.has_action(action):
		InputMap.add_action(action)
		
	InputMap.action_add_event(action, key_event)

func _input(event):
	if(Input.is_action_just_pressed("Save")):
		print("Save")
	if(Input.is_action_just_pressed("Select S")):
		print("Select S")
	
	if(Input.is_action_just_pressed("Run")):
		print("Run")
	if(Input.is_action_just_pressed("Jump")):
		print("Jump")
	if(Input.is_action_just_pressed("Super Jump")):
		print("Super Jump")

Bugsquad edit: Fixes #18793.

Merge request reports