This behavior can be achieved by just adding an “FKey” parameter to the bound method.
Create an Action input mapping on the ProjectSettings, then add all the key binds you need (AnyKey if you want all keys). Then use it like this on your code:
MyPlayerController.h
virtual void SetupInputComponent() override;
void TryAction(FKey key);
MyPlayerController.cpp
void AMyPlayerController::SetupInputComponent() {
Super::SetupInputComponent();
InputComponent->BindAction("MyAction", EInputEvent::IE_Pressed, this, &AMyPlayerController::TryAction);
}
void AMyPlayerController::TryMorph(FKey key)
{
FName keyName = key.GetFName();
}