UMG - Keyboard shortcuts

Hello,

So i have my UMG HUD working very well, i had no problem to set it up, i think the umg guys did a great job so far.
My issue is that it works well with the mouse but i have some issues with the keyboard. I would like to call a button “OnClick” event from a keyboard key. I though i could in the event graph by taking my button variable and call the event on it, but it doesn’t show any events. The only way really to have access to these events is in the designer tab.
Basically i would like to be able to call events from a node in the event graph, like it’s done for the other blueprints.

So if someone can help me with using buttons with the keyboard it would be awesome, thanks.

There’s three things I can think of, in order to make it work.

  1. Create a custom event for what your “OnClick” is meant to trigger and plug it into the button’s “OnClick” as well as your keyboard shortcut in your player controller. (The problem with this method is that you won’t trigger the button visually switching states from normal to hover or to pressed)

  2. Have your keyboard key press set the focus to the UMG button (The problem with this method is that you require to hit enter once you’ve assigned focus, essentially making the button use a two key process instead of one)

  3. You could also just create your own widget that could mimic the button and manually change an image component based on your keyboard key press.

Hope this helps.

Yeah it does thank you. I thought of what you said in 1) after i wrote my question, i was waiting for a better idea to come up but i think it’s the best solution for now. Im pretty sure keyboard support will get better in future updates.

Thx for your answer.

Shortest solution for me was using Delegates

In the project settings I’ve set an action that I want to bind the shortcut keys to

95385-2_projectsettings.png

In My Player Controller (extends the player controller), I’ve created a delegate with a simple firing configuration. In the right pannel you can add inputs and I forwarded the key pressed

[EDIT] Also, you can check “Fire when paused” on this node if you need it to execute when the game is paused via the “Set Game Paused” node

In my UMG Construct Just added the delegate to a new custom node

2 Likes

Worked great! Thanks!

Old thread, but I was chasing problem of getting Action Events to be seen/trigger UMG widget. Figured out to register the UMG as listening for specific Action Events and using a delegate. Entirely contained within the widget (except, of course, the Action Events identified in Project Settings):

On widget Event Construct, added calls to “Listen for Input Action” (and identified the Action Event I wanted); needed one for each Action Event I wanted. Created a delegate right there to handle each Action Event. In effect, instead of just putting the Action Event handler in the widget (not allowed) I had to create a Listener to then trigger a custom Action Event handler.

I like this since I don’t need to adjust anything else – just add the listener and triggered events in the widget blueprint.

236900-minimap-actionmap.png

1 Like

This was exactly what I was looking for and didn’t find. This is better because it works for all action mappings and you need to modify only in your UMG

But the problem with the “Listen for Input Action” is he only works if your focus are at the game, its good for example, to a rpg, you have a skill slot on the slot/icon 1… you press 1 so the icon of that skill glow, but if u use the mouse and click on that skill slot/icon, you will set the focus to the UMG and after that if u press 1 again, nothing happens.

A little old question but i think someone might find this useful

This is how i solved a similar problem where i wanted to interact with gamepad and keyboard only in a menu with game mode set to UI only, and use B button on an xbox controller as the Accept button, no mouse at all.

On UMG Override the OnKeyDown Function

Get Key is used only for the IsValid & Branch, I noticed it was producing odd behaviour if the Keyboard Menu Key was pressed. Then on the Event Graph I made a custom event (SelectorKey)

What it does is, it gets every button mapping for every action and compares it with the pressed key, then if the key exist within an action mapping, get its ActionName, convert it into a string an use a switch on string, this way i control the path.

The problems i have found to my solution, is that it must be implemented in each UMG and must have keyboard focus and that you cant set speed it does check, so to scroll by holding the button for example, it does it too fast, thats why i used the Is Repeat node, so it only does it once.

4 Likes

Thank you very much for this answer!

Please note that this will not work in UI only input mode.

Exactly! And if you have UI and game it has an issue with the mouse getting lost when you click on the background.

Personally find approach via “OnKeyDown” parsing quite reasonable, so i wonder why this answer is downvoted. It doesn’t look like anything bad for me