What is the c++ equivalent of the key press BP node?


In Blueprints, there are these nice nodes for key presses (and releases).
i wonder how to do that in c++.
Any tutorials I found so far are all about mapping stuff to action or axis mappings.

All I want to is execute some code in my player controller when the player presses the ‘X’ key for example.
How would I do that?


You should be using Action and Axis mappings for all player input, including in blueprints. As far as I know, that’s the only good way to do it.

yeah you should be using Action and Axis mappings, nevertheless you can check whenever somethings is pressed or not directly from the APlayerController class .


And what is the key press node then for?


And how exactly would I do that?

I’m still beginner level in Unreal++. :slight_smile:

hey @KVogler yep here the name: bool IsInputKeyDown(FKey Key), you can even call it with blueprint it is a BlueprintCallable event

Debug commands mostly, or super early prototyping.

Action / Axis Mappings are what you should use for any input that the end user interacts with. This let’s the user re-map keys to various buttons / joysticks / etc without you having to change your code. If you use Key Press / etc, you are hard coding your logic to that specific key.

Ah ok. I know about action mappings.
But its the early prototype phase I’m actually in.
Just using this to trigger and test some code.

When I call this function, I would only get the result (key state) at the time of evaluation right?
So, I need to check that periodically, like in ticking?
The BP node doesn’t seem to be ‘ticking’…

The level consists of a single character blueprint, so any actors aren’t auto receiving the input and character is spawned in the world.

Even in early prototype phase, it’s pretty simple to just create some actions, and then throw together a PlayerController or Input blueprint and wire them up there.