Shift Input in Editor Utility Widget

Is there a way to tell if the shift key is being pressed while interacting with an editor utility widget? I can’t get input events from the player controller because, well, there’s no player while the widget is running. I would appreciate any ideas. Thanks in advance.

1 Like

Same as with a regular widget:

4 Likes

That looks perfect! How do I get that “On Key Down” function? It doesn’t come up if I right click and type “Key Down”, even with context sensitivity off. I found this (UUserWidget::OnKeyDown | Unreal Engine Documentation) But it doesn’t say how to implement it. Sorry if that seems like a basic question. I’m still fairly new to widgets.

1 Like

No worries. Widgets (just like actors) come with a ton of overrides:

Returning Handled will stop the input from being processed again (by another widget or the player controller). Returning Unhandled will let input tunnel, so you could have another entity detect it after it’s been processed by a widget.

To process keyboard input a widget must have focus (otherwise the Player Controller may consume said input) but in the case of EUW that’s usually not a problem since you’re very likely to select it manually anyway, and:

there’s no player while the widget is running

2 Likes

Thanks a lot! That worked a treat. Only thing is keeping focus on the widget. I could set the focus on the widget when it was generated, but as soon as I clicked on anything else (either a button in the widget or something in the scene), the widget lost focus. I made a little function to give the widget focus and executed it after any button is pressed, which helps. However, it’s still possible to click something else causing the focus to be lost. Then I can’t get it back until a button is pressed.

For this widget, this solution works fine, so I think I’m good. Thanks, Everynone! But if anyone else should try to tackle this particular problem, that’s where I left off.

If you look at the list in the pic, you’ll notice onFocusLost, perhaps you could override it and reset the focus to Self. This way this widget will always have it. Not sure how that’d work with EUW, though.

I had a similar requirement, I wanted to do some other actions when shift or ctrl is beeing pressed. The approaches above worked, but sadly I had to manually click on a widget.

What worked way better for me is setting “IsFocusable” to true. Then the key down/up events get fired once I clicked somewhere in the editor widget.

Source: UI Widget key events OnKeyDown/OnKeyUp not generated - #5 by isgoed

Trying to follow along with this in UE 5.3.2 - I can over-ride the OnKeyDown function as above, but I can’t drag it into my Event Graph !
I just get the message ‘This function was not marked as Blueprint Callable and cannot be placed in a graph !’.
I can’t find anywhere to change this.
Any chance you could add some info about using the over-riden function ?
Thanks.

1 Like

No need to place it in the graph, it fires automatically when input is received.

Thanks. but then, what node do I catch the output with ? ie How do I test for shift being held in the graph ?

1 Like

Have the onKeyDown set a variable, you can then query it elsewhere.

Thanks. but then, what node do I catch the output with ?

Or simply fire an event / function from the keydown. Perhaps there’s no need to listen, you’ve already listened. Now do what needs to be done.

Perfect, thank you

1 Like

Quick note for other beginners in case it helps anyone.
I set a global boolean variable for whether shift was down from inside the OnKeyDown. Then I over-rode OnKeyUp as well, & again, tested for whether it was shift that had come up. If it was, set the same boolen variable to false.
Then I could check if the variable was true from the main graph or within any of my functions.