Enhanced Input key with modifier?

I am trying to use the Enhanced Input plugin but I can’t find a way to add a mapping for a keyboard key with a modifier to the input mapping context. For example I want to add two separate input actions and use shift+A and alt+A for them respectively.

4 Likes

So I actually found out how to do this but I’m not a big fan of this approach since the whole idea behind input actions is that they are input method/key binding agnostic.

I noticed the “Chorded Action” trigger and this basically allows you to have an action only triggered when another one is triggered. Using these I created separate input actions for my keyboard modifier keys. They all have the same properties. I unchecked “Consume input” but this depends on your needs.

I then created two input mapping contexts. I add the keyboard modifier action mappings to the keyboard mapping context so that I can just always have that mapping loaded and make use of those actions in other mappings.

Then I added some actions that have the same key assigned to them but only one of them triggers based on the keyboard modifier because of the “Chorded Action” trigger.

I added the context mappings and added event handlers for the input actions. Note that I had to use a branch to check for the action value when coming from the Started exec pin because the started event may be called with a false value. I don’t know why but I guess this is just how it comes together. If you use the triggered exec pin it seems you can go without it. I used Started here because i like to have a single event instead of all the time but this depends on your use case.

I also used a higher priority for the keyboard action mapping context so make sure it gets the input first and together with the “Consume Input” being false I can still later use any modifier key for any other key binding.

Now I can press Shift+1 to activate ability 1 and Alt+1 to activate ability 2!

19 Likes

WOW, this is actually so annyoing, especially with widgets. Hope this will get addressed.

I’ve found another, more elegant way to do it! Inspired by the solutions proposed here.

In my case, I have two separate actions mapped to the scroll wheel. The first action (IA_CameraZoom) is mapped only to the scroll wheel for zooming in/out the camera view (my game is third-person BTW). The second (IA_PlayerMovSpeedChanged) is a combination of holding the right mouse button + the scroll wheel to change the character’s movement speed (exactly like the shortcut used in the editor). Here’s my setup using only one context mapping and three input actions.

Pay attention to the button mapped to IA_PlayerMovSpeedChanged and IA_CameraZoom. I have two input actions mapped to the same button (scroll wheel), but they have two different purposes in the system! I need to hold the right mouse button and scoll to actually trigger IA_PlayerMovSpeedChanged. Otherwise, only IA_CameraZoom is triggered when using the scroll wheel.

3 Likes

It seems in 5.3 I was not able to trigger chorded action, when chord modifier was in another input mapping. Had to workaround by placing modifier into the same input mapping context.

Anyone know who to get to the blueprint level for an input action (if possible)? The last image shows the ModifierKey approach (Enhanced Input key with modifier - #2 by shq300)… If not possible, can someone shed light on how that poster did that?

I believe they are creating a new blueprint class deriving from the InputTrigger class (as they said as much :))

To do this you can just right click in the ContentBrowser and select Blueprint > Blueprint Class and then select InputTrigger as the base class

You will then be able to override the UpdateState function as shq300 did

Just wanted to provide you with little tut I did on this topic:

1 Like