C++ Input Event Disabling / Circumventing

So I’ve got some keybinds set up for my game. They all work handily. I’ve also got some non-keybind (raw key/axis state processing) going on in my player controller (for some UI stuff.) That all works nicely, too. Getting them to play nicely together is where I’m hitting issues.

What I want to do:

  • Disable any keyboard input (consume all keyboard events) if a condition is met (i.e. mouse or joystick keybinds still work, but no keyboard ones do)
  • Add in some pre-processing to mouse events (key and axis) after their state update, but before the bind delegates are executed, and optionally stop the delegates from firing (consume the events.)

I’m checking through the UPlayerInput class and the ProcessInputStack method (and all the methods it calls, which are all non-virtual) seems to update key states AND fire keybind delegates. Is there a way to circumvent the key binds / consume keys without just copy/pasting the whole PlayerInput class to get around the non-virtual methods?

Edit: I had a look at this thread, https://answers.unrealengine.com/questions/3014/best-way-to-intercept-input-events-for-hud-if-not.html, but it does not cover the system working in unison, only 1 being used in place of the other.

Hi TTaM,

For your first scenario, have you tried setting up a bool that switches on and off depending on your condition, then your keyboard input code is contained within an if statement checking the current state of the bool?

I am not sure exactly what you are trying to accomplish in the second scenario. Could you possibly explain a little bit more? It may be a little more complicated, but you might be able to accomplish this with something similar to what I mentioned above.

Thanks for the reply, . I did that at first, but I realised that people may change the keybind. I want to stay away from static key->action linking. For instance, there is a keybind to move left. Somebody may bind this to mouse4 instead of ‘w’, but I only want to block the action when the ‘w’ is used, not when mouse4 is used.

I have the bool set up to block the input, I just can’t use it because I don’t know the source of the keybind delegate being triggered. I don’t want to unilaterally block all actions which are “probably” keyboard oriented, that’s just sloppy coding.

The second is problem is this. I currently have a “keybind” for the left mouse button (which people can change if they want to.) This performs some action within the game. However, I also have a non-Slate UI which interacts with mouse clicks. I want to to tell the input system, whenever any mouse button is pressed, for any keybind, to check whether the UI has processed the mouse event first. A sort of “priority” system.

The first problem could be thought of in the same way, with the UI taking priority over the keybinds under certain conditions (such as editing text.) However, I do not know how, with the UE4 input system, to add in such a priority system. The ProcessInputStack checks the keystates and immediately executes the delegates, without any possible user processing in the middle.

Can I ask what the purpose of blocking the keyboard input is intended for? Generally the way this should work is that you have your input component stack and if you have something consuming the keyboard keys then the lower priority component will never see the key pressed. So you could have something consuming keyboard left in a higher priority component so it wouldn’t make it to the lower priority one, but since nothing consumes the mouse 4 it would go through.

In terms of your UI where are you passing input to your UI system? I’m imagining that you will need to subclass GameViewport, route input to your UI and then send it to the player controller. If you’re using the HUD hitbox system for this, there isn’t currently anything in place to block input processing if the HUD is clicked, but it wouldn’t be too hard to set something up in APlayerController::InputKey to accomplish it.

I have a UI component that supports text editing and I don’t want any keybind that is triggered by the keyboard to be executed while that component has focus. I think I could accomplish this by blocking the passing on of keyboard (pressed) events during the InputKey method? That would stop the accumulators from triggering the key presses, I hope.

I suppose I can solve the mouse click issue by having an InputComponent which has 2 of its own keybinds (not set up in ini files) for left and right click, these would override the ones from the config files and the regular keybinds wouldn’t be run. Or just use the above InputKey method for this as well.

Thank you, . Your post has given me some insight. I shall report back if it works!

Yes, it seems to be working. I shunt everything through my UI in the InputKey event in PlayerController. If it’s a pressed event and the UI consumes it, it doesn’t pass it on to the PlayerInput class for accumulating.