How to register ESC or Tab when widget text box has keyboard focus?

Hello all!

I am building a chat box in a multiplayer project. I want to make it so after typing and sending your message, pressing ESC refocuses to game. (and eventually pressing TAB to switch between all chat and team chat.)

I can’t figure out how to detect ESC or Tab input when text box has keyboard focus.

Here’s my setup:
In event begin play, I’m setting input mode to game only:
eventbeginplay.PNG
Then, by pressing T, it focuses to chat text box, so I can immediately start typing a message without having to click the text box with my mouse:


Then, here’s what ESC is bound to do in player controller:

I have this debug print string setup on event tick to monitor what the widget has in focus:

Here’s what my results are:

Right as I go in game, where I can control my player:
Any user focus: false/ Has user focus: false/ Keyboard focus: false

Pressing T once, where I can now type a message:
Any user focus: false/ Has user focus: false/ Keyboard focus: true

Pressing ESC once, now I’m stuck in some weird interface mode where WASD registers my character movement input, but my mouse is free to move around, and if I want to look around as player, I have to right click drag the screen (I’m using third person BP template). I can use my mouse to click the textbox to focus back on it.
Any user focus: true/ Has user focus: true/ Keyboard focus: true

Pressing ESC twice, does my intended effect, bringing me back to game only input.
Any user focus: false/ Has user focus: false/ Keyboard focus: false

This tells me somewhere is consuming my ESC input (and Tab input) before my player controller can handle it. Anyone know where and how I can modify it to do what I want?

Thank you!

If you’re still dealing with this, or for anyone else who’s found this, you’re going to want to make a custom base textbox widget for use throughout all of your UMG. I don’t know if this exact answer will help you but it should put you on the right path to figuring out a solution. Inside this custom widget, override the event OnPreviewKeyDown. Overriding this event is a chance to change widget behavior before it consumes input (OnKeyDown occurs after the widget has already decided to handle that KeyEvent). You will want to right click the OnPreviewKeyDown and add a call to parent function, then plug the inputs from the overridden executable into the parent function, and then plug in a branch. Any keys you don’t want the widget to handle with its default functionality, you can pass in a different direction on this branch. Be sure to pass the generic output with the EventReply from the parent function for the generic case though. So in this example, you would check to see if the KeyEvent had a Key == Esc or == Tab, and then if so, it sounds like you’d pass a Handled EventReply through a different return node in that case.

See Nick’s reply here for more info. https://forums.unrealengine.com/deve…board-nav-keys

Anyway, that didn’t work for me, so in OnPreviewKeyDown I just added an Event Dispatcher to send a virtual tab press through my usual event that handles that.

2 Likes

thanks, I caught the right button in OnPreviewKeyDown and my similar problem was solved