Hi. Does somebody know if in cpp code is an event that is called when you press any keyboard button? And, can I bind my function to that event?
In your player controller
.h file
virtual void SetupInputComponent() override;
void KeyPressed(FKey key);
.cpp
void ACarPlayerController::SetupInputComponent()
{
Super::SetupInputComponent();
InputComponent->BindAction("My Action", EInputEvent::IE_Pressed, this, &YourPlayerController::KeyPressed);
}
void YourPlayerController::KeyPressed(FKey key)
{
// do the magic
}
4 Likes
Yes. I know about that, but can I do it without editor?
This is C++ code, not editor code.
Yes, but I’ve replied to not your answer. And can you say your code work without creating of action in the editor like in this case (How to get Key in C++? - #9 by ImZeperoni)
?
1 Like
Aha, not that I’m aware of. Not sure how it’s being done before this. Actually, these are defined in: Config/DefaultInput.ini
Why do you want to avoid action binding?
I want to create a UE plugin that listens to the keyboard, and I don’t want to force the user to make a new action
1 Like
void AMyPlayerController::SetupInputComponent()
{
Super::SetupInputComponent();
if (WasInputKeyJustPressed(EKeys::AnyKey))
{
//
}
}