Keyboard event in C++

Sure. UAnimInstance has a function TryGetPawnOwner(), which returns APawn pointer - object, which owns this UAnimInstance. APawn has a function GetController - get a pointer to controller of this pawn. If you use UAnimInstance at your player character, using TryGetPawnOwner()->GetController() will return PlayerController. After that, just access variable from controller.
Example:

void UYourAnimInstance::NativeInitializeAnimation() {
    APawn* ControlledPawn = TryGetPawnOwner() // get owner pawn
    if(ControlledPawn){ //check if ControlledPawn != nullptr
        Controller = Cast<AYourControllerType>(ControlledPawn->GetController()) //get controller, cast it to your controller type and save to UYourAnimInstance member of type AYourControllerType*
    }
}

void UYourAnimInstance::NativeUpdateAnimation(float DeltaSeconds) {
    if(Controller){ // if Controller valid
        bool Data = Controller->Data; // get a variable from controller
    }
}

It’s just an example, maybe there is a better way to access variables in PlayerController from AnimInstance.