# Enhanced Input - Detect Gamepad vs Keyboard Input

**URL:** <https://forums.unrealengine.com/t/enhanced-input-detect-gamepad-vs-keyboard-input/1231533>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [July 17, 2023, 12:41pm UTC](https://forums.unrealengine.com/t/enhanced-input-detect-gamepad-vs-keyboard-input/1231533 "2023-07-17T12:41:48Z")\
**Posts on this page:** 1\
**Showing post:** 19

<div class="post-metadata">

**Author:** ![elguapador](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@elguapador](https://forums.unrealengine.com/u/elguapador)\
**Post date:** [May 28, 2025, 8:03am UTC](https://forums.unrealengine.com/t/enhanced-input-detect-gamepad-vs-keyboard-input/1231533/19 "2025-05-28T08:03:35Z")

</div>

An alternative to this if you don’t have (and can’t be bothered to make and configure a new input class):

```auto
// 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.

---

_[View the full topic](https://forums.unrealengine.com/t/enhanced-input-detect-gamepad-vs-keyboard-input/1231533)._
