An alternative to this if you don’t have (and can’t be bothered to make and configure a new input class):
// playercontroller.cpp
void AMyPlayerController::BeginPlay()
{
Super::BeginPlay();
UInputDeviceSubsystem* InputDeviceSubsystem = GEngine->GetEngineSubsystem<UInputDeviceSubsystem>();
InputDeviceSubsystem->OnInputHardwareDeviceChanged.AddDynamic(this, &AGamePlayerController::OnInputHardwareChanged);
bIsUsingController = InputDeviceSubsystem->GetMostRecentlyUsedHardwareDevice(GetLocalPlayer()->GetPlatformUserId()).PrimaryDeviceType == EHardwareDevicePrimaryType::Gamepad;
}
void AMyPlayerController::OnInputHardwareChanged(const FPlatformUserId UserId, const FInputDeviceId DeviceId)
{
UInputDeviceSubsystem* InputDeviceSubsystem = GEngine->GetEngineSubsystem<UInputDeviceSubsystem>();
bIsUsingController = InputDeviceSubsystem->GetMostRecentlyUsedHardwareDevice(UserId).PrimaryDeviceType == EHardwareDevicePrimaryType::Gamepad;
}
This only fires when input from a different hardware input is detected, rather than every time you press any key. Confirmed working on 5.3.