11#include "Engine/Engine.h"
12#include "Modules/ModuleManager.h"
13#include "EnhancedRawInput.h"
14#include "EnhancedRawInputSettings.h"
15#include "Framework/Application/SlateApplication.h"
16#include "Windows/WindowsApplication.h"
17#include "GameFramework/HUD.h"
22constexpr auto MaxHidDevices = 16;
25constexpr auto MaxHidPovSwitches = 4;
28constexpr auto HidUsagePage = 0x01;
29constexpr auto HardwareUsageJoystick = 0x04;
30constexpr auto HardwareUsageGamepad = 0x05;
31constexpr auto HidUsagePov = 0x39;
33DECLARE_DELEGATE_OneParam(FHidDeviceConnectedDelegate, FString );
36struct ENHANCEDRAWINPUT_API FWindowsHidApi
39 typedef BOOLEAN(*HidD_GetSerialNumberString_Type)(HANDLE HidDeviceObject, PVOID Buffer, ULONG BufferLength);
40 typedef BOOLEAN(*HidD_GetManufacturerString_Type)(HANDLE HidDeviceObject, PVOID Buffer, ULONG BufferLength);
41 typedef BOOLEAN(*HidD_GetProductString_Type)(HANDLE HidDeviceObject, PVOID Buffer, ULONG BufferLength);
42 typedef NTSTATUS(*HidP_GetCaps_Type)(PHIDP_PREPARSED_DATA PreparsedData, PHIDP_CAPS Capabilities);
43 typedef NTSTATUS(*HidP_GetButtonCaps_Type)(HIDP_REPORT_TYPE ReportType, PHIDP_BUTTON_CAPS ButtonCaps, PUSHORT ButtonCapsLength, PHIDP_PREPARSED_DATA PreparsedData);
44 typedef NTSTATUS(*HidP_GetValueCaps_Type)(HIDP_REPORT_TYPE ReportType, PHIDP_VALUE_CAPS ValueCaps, PUSHORT ValueCapsLength, PHIDP_PREPARSED_DATA PreparsedData);
45 typedef NTSTATUS(*HidP_GetUsages_Type)(HIDP_REPORT_TYPE ReportType, USAGE UsagePage, USHORT LinkCollection, PUSAGE UsageList, PULONG UsageLength, PHIDP_PREPARSED_DATA PreparsedData, PCHAR Report, ULONG ReportLength);
46 typedef NTSTATUS(*HidP_GetUsageValue_Type)(HIDP_REPORT_TYPE ReportType, USAGE UsagePage, USHORT LinkCollection, USAGE Usage, PULONG UsageValue,PHIDP_PREPARSED_DATA PreparsedData, PCHAR Report, ULONG ReportLength);
47 typedef NTSTATUS(*HidP_GetData_Type)(HIDP_REPORT_TYPE ReportType, PHIDP_DATA DataList, PULONG DataLength, PHIDP_PREPARSED_DATA PreparsedData, PCHAR Report, ULONG ReportLength);
52 HANDLE DllHandle =
nullptr;
54 HidD_GetSerialNumberString_Type HidD_GetSerialNumberString;
55 HidD_GetManufacturerString_Type HidD_GetManufacturerString;
56 HidD_GetProductString_Type HidD_GetProductString;
57 HidP_GetCaps_Type HidP_GetCaps;
58 HidP_GetButtonCaps_Type HidP_GetButtonCaps;
59 HidP_GetValueCaps_Type HidP_GetValueCaps;
60 HidP_GetUsages_Type HidP_GetUsages;
61 HidP_GetUsageValue_Type HidP_GetUsageValue;
62 HidP_GetData_Type HidP_GetData;
66struct ENHANCEDRAWINPUT_API FHidAxis
117struct ENHANCEDRAWINPUT_API FHidButton
139struct ENHANCEDRAWINPUT_API FHidPov : FHidAxis
144 LastButtonStates.Init(
false, MaxHidPovSwitches);
155 TArray<bool> LastButtonStates;
185struct ENHANCEDRAWINPUT_API FHidDevice
191#ifdef MULTI_CONTROLLER_SUPPORT
196 UserId(PLATFORMUSERID_NONE),
259class ENHANCEDRAWINPUT_API FEnhancedRawInputWindows :
public IEnhancedRawInput, IWindowsMessageHandler
261 friend class UEnhancedRawInputSettings;
262 friend class UEnhancedRawInputLibrary;
265 FEnhancedRawInputWindows(
const TSharedRef<FGenericApplicationMessageHandler>& InMessageHandler);
266 virtual ~FEnhancedRawInputWindows()
override;
269 virtual void SetBindings(
const FString InterfaceName)
override;
270 virtual void SetMultiControllerBinding(
const int32 ControllerId,
const FString InterfaceName);
271 virtual void SetAxisBinding(
const FString InterfaceName,
const int32 AxisUsage,
const FName KeyName)
override;
272 virtual void SetButtonBinding(
const FString InterfaceName,
const int32 ButtonIndex,
const FName KeyName)
override;
273 virtual void SetPovAxisBinding(
const FString InterfaceName,
const int32 PovIndex, FName KeyName)
override;
274 virtual void SetPovButtonBinding(
const FString InterfaceName,
const int32 PovIndex, TArray<FName> KeyNames)
override;
278 virtual void SetChannelValue(int32 ControllerId, FForceFeedbackChannelType ChannelType,
float Value)
override {}
279 virtual void SetChannelValues(int32 ControllerId,
const FForceFeedbackValues &Values)
override {}
280 virtual bool Exec(UWorld* InWorld,
const TCHAR* Cmd, FOutputDevice& Ar)
override {
return false; }
281 virtual void SetMessageHandler(
const TSharedRef<FGenericApplicationMessageHandler> &InMessageHandler)
override;
282 virtual void Tick(
float DeltaTime)
override;
283 virtual void SendControllerEvents()
override;
284 virtual bool SupportsForceFeedback(int32 ControllerId)
override {
return false; }
288 virtual bool ProcessMessage(HWND Hwnd, uint32 Msg, WPARAM WParam, LPARAM LParam, int32& OutResult)
override;
311 TMap<int32, FHidAxis>
GetAxisInfo(
const FString& InterfaceName);
316 TArray<FHidPov>
GetPovInfo(
const FString& InterfaceName);
336 typedef CONFIGRET(*CM_Register_Notification_Type)(PCM_NOTIFY_FILTER pFilter, PVOID pContext, PCM_NOTIFY_CALLBACK pCallback, PHCMNOTIFICATION pNotifyContext);
337 typedef CONFIGRET(*CM_Unregister_Notification)(HCMNOTIFICATION NotifyContext);
339 CM_Register_Notification_Type CmRegisterNotification;
340 CM_Unregister_Notification CmUnregisterNotification;
341 HANDLE Cfgmgr32DllHandle =
nullptr;
342 HCMNOTIFICATION NotifyContext;
344 bool bRefreshDevices =
false;
345 FDateTime DeviceRefreshStart;
347 bool bDeviceRegistered =
false;
348 int32 LastMultiControllerID = -1;
351 TArray<FString> ActualConnectedDevices;
356 void QueryDeviceCaps(
FHidDevice &Device)
const;
358 FHidDevice *FindDeviceByHandle(HANDLE Handle);
360 void ShowDebug(AHUD* HUD, UCanvas* Canvas,
const FDebugDisplayInfo& DisplayInfo,
float& YL,
float& YPos);
362 static bool TryRegisterInputDevice();
364 static bool IsMultiController(
const FName& KeyName,
const FHidDevice &Device);
float Offset
Axis offset as configured.
Definition EnhancedRawInputWindows.h:99
int32 Max
Maximal value, as reported from the driver.
Definition EnhancedRawInputWindows.h:96
FName KeyName
Bound Key name.
Definition EnhancedRawInputWindows.h:84
int32 Min
Minimal value, as reported from the driver.
Definition EnhancedRawInputWindows.h:93
ERawInputAxisOutputType OutputType
Configured output type.
Definition EnhancedRawInputWindows.h:90
bool bIsInverted
Whether is axis inverted (from Configuration)
Definition EnhancedRawInputWindows.h:102
float GetValue() const
Value of this axis, normalised, inverted and/or in specific format, according to configuration.
Definition EnhancedRawInputWindows.cpp:49
bool bIsEnabled
TRUE if axis is enabled in settings.
Definition EnhancedRawInputWindows.h:87
bool HasValue() const
Whether this axis has valid value.
Definition EnhancedRawInputWindows.cpp:72
bool bHasChanged
Whether value has changed since last HID event.
Definition EnhancedRawInputWindows.h:105
int32 Value
Current value of this axis.
Definition EnhancedRawInputWindows.h:81
Stores information and data about a HID Device.
Definition EnhancedRawInputWindows.h:186
uint32 ButtonUsageMin
Internally used.
Definition EnhancedRawInputWindows.h:234
int32 ControllerId
Internal unique controller ID.
Definition EnhancedRawInputWindows.h:213
FPlatformUserId UserId
Current User ID for this device, as reported from Unreal engine.
Definition EnhancedRawInputWindows.h:237
bool bIsActive
Whether the device is active and being handled.
Definition EnhancedRawInputWindows.h:243
EInputDeviceConnectionState ConnectionState
Connection state for this device.
Definition EnhancedRawInputWindows.h:246
FInputDeviceId DeviceId
Current Device ID for this device, as reported from Unreal engine.
Definition EnhancedRawInputWindows.h:240
int32 MultiControllerId
Multi-controller Id.
Definition EnhancedRawInputWindows.h:216
FString InterfaceName
Interface name as reported from driver.
Definition EnhancedRawInputWindows.h:222
FString SerialNumber
Serial number as reported from driver, may be empty.
Definition EnhancedRawInputWindows.h:228
TArray< FHidPov > PoVs
Information about all PoVs for this device.
Definition EnhancedRawInputWindows.h:255
TArray< FHidButton > Buttons
Information about all buttons for this device.
Definition EnhancedRawInputWindows.h:249
int32 NumberInputValueCaps
Number of HID Value (Axis) capability's, internally used.
Definition EnhancedRawInputWindows.h:219
HANDLE Handle
Internal HID Handle.
Definition EnhancedRawInputWindows.h:204
TArray< uint8 > PreParsedDataBuffer
Pre parsed HID report descriptor. Used internally.
Definition EnhancedRawInputWindows.h:207
FString ProductName
Product name as reported from driver, may be empty.
Definition EnhancedRawInputWindows.h:231
RID_DEVICE_INFO DeviceInfo
Device info from driver, see https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-r...
Definition EnhancedRawInputWindows.h:210
TMap< int32, FHidAxis > Axis
Information about all axis for this device.
Definition EnhancedRawInputWindows.h:252
FString Manufacturer
Manufacturer name as reported from driver, may be empty.
Definition EnhancedRawInputWindows.h:225
bool HasAxisValue() const
Checks if axis is configured and has valid value.
Definition EnhancedRawInputWindows.cpp:155
ERawInputPovOutputType PovOutputType
Output type as configured.
Definition EnhancedRawInputWindows.h:161
float GetAxisValue() const
Returns (normalised, depends on output type) value.
Definition EnhancedRawInputWindows.cpp:119
void UpdateButtonValues()
Updates the virtual D-PAD buttons, internally used.
Definition EnhancedRawInputWindows.cpp:90
uint16 DataIndex
Data index, internally used.
Definition EnhancedRawInputWindows.h:149
int32 GetPovValueDeg() const
Get Value of this POV.
Definition EnhancedRawInputWindows.cpp:79
TArray< bool > CurrentButtonStates
Sates of the virtual D-Pad Buttons.
Definition EnhancedRawInputWindows.h:152
bool HasButtonValue(uint32 Index) const
Checks if a button is configured and has valid value.
Definition EnhancedRawInputWindows.cpp:150
TArray< FName > ButtonKeyNames
Keynames as configured.
Definition EnhancedRawInputWindows.h:158
Internal structure for function pointers to Windows APIs. Not for public use.
Definition EnhancedRawInputWindows.h:37