WasInputkeyJustPressed/IsInputKeyDown always false

Hi,

I need to return a boolean from a Keypress in Unreal.

When I call this in AMyPawn::BeginPlay() it works just fine but I can just call a void function from it.

void AMyPawn::BeginPlay()
 { 
    Super::BeginPlay();
    
     APlayerController* PC = GetWorld()->GetFirstPlayerController();
     PupilUser->InputComponent->BindKey(EKeys::Enter, IE_Pressed, this,  &AMyPawn::PrintTestStringToScreen);
  }
        //Prints me a beautiful string on my Screen

So I tried different options like

void AMyPawn::BeginPlay()
{
	Super::BeginPlay();

if(PC->WasInputKeyJustPressed(EKeys::AnyKey);	
GEngine->AddOnScreenDebugMessage(-1, 50.f, FColor::Red, TEXT("Key pressed"));

if(PC->IsInputKeyDown(EKeys::AnyKey);	
GEngine->AddOnScreenDebugMessage(-1, 50.f, FColor::Red, TEXT("Key pressed"));

}

Compiling ist just fine of them but if I press a key nothing happens. Can You please help me and tell me what I am missing or doing wrong?

Thank You!

After a couple of days I found the solution! You can’t call WasInputKeyJustPressed() in BeginPlay(). It muss be called from Tick().
Solution that works:

void AMyPawn::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

APlayerController* PC= GetWorld()->GetFirstPlayerController();

if(PC->WasInputKeyJustPressed(EKeys::AnyKey);    
 GEngine->AddOnScreenDebugMessage(-1, 50.f, FColor::Red, TEXT("Key pressed"));

}

धनवाद (Eng: very very thank You)