- In Settings | Project Settings | Input, define a new Action Mapping for your hot key event, for example, HotKey_UIButton_Spell:

- Wire up the event to your UI's function call either in Blueprints or in C++ code. In our case, I will add it to the AWarrior class we created previously by adding it to the SetupPlayerInputComponent function:
#include "Chapter_06GameModeBase.h"
// ...
// Called to bind functionality to input
void AWarrior::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
check(PlayerInputComponent);
PlayerInputComponent->BindAxis("Forward", this,
&AWarrior::Forward);
PlayerInputComponent->BindAxis("Back", this, &AWarrior::Back);
PlayerInputComponent->BindAxis("Right", this, &AWarrior::Right);
PlayerInputComponent->BindAxis("Left", this, &AWarrior::Left);
PlayerInputComponent->BindAction("Jump", IE_Pressed, this,
&AWarrior::Jump);
// Example of adding bindings via code instead of the
// editor
FInputAxisKeyMapping backKey("Back", EKeys::S, 1.f);
FInputActionKeyMapping jump("Jump", EKeys::SpaceBar, 0, 0,
0, 0);
GetWorld()->GetFirstPlayerController()->PlayerInput-
>AddAxisMapping(backKey);
GetWorld()->GetFirstPlayerController()->PlayerInput-
>AddActionMapping(jump);
// Calling function for HotKey
auto GameMode = Cast<AChapter_06GameModeBase>(GetWorld()-
>GetAuthGameMode());
auto Func = &AChapter_06GameModeBase::ButtonClicked;
if(GameMode && Func)
{
PlayerInputComponent->BindAction("HotKey_UIButton_Spell",
IE_Pressed, GameMode,
Func);
}
}
- Compile your script and then open the World Settings by going to Settings | World Settings. Under Selected GameMode, set the Default Pawn Class to BP_Warrior. You should now notice that you can either press your key or press the button to execute the ButtonClicked function we created in the previous recipe!