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"
21constexpr auto MaxHidDevices = 16;
24constexpr auto MaxHidPovSwitches = 4;
27constexpr auto HidUsagePage = 0x01;
28constexpr auto HardwareUsageJoystick = 0x04;
29constexpr auto HardwareUsageGamepad = 0x05;
30constexpr auto HidUsagePov = 0x39;
32DECLARE_DELEGATE_OneParam(FHidDeviceConnectedDelegate, FString );
38 typedef BOOLEAN(*HidD_GetSerialNumberString_Type)(HANDLE HidDeviceObject, PVOID Buffer, ULONG BufferLength);
39 typedef BOOLEAN(*HidD_GetManufacturerString_Type)(HANDLE HidDeviceObject, PVOID Buffer, ULONG BufferLength);
40 typedef BOOLEAN(*HidD_GetProductString_Type)(HANDLE HidDeviceObject, PVOID Buffer, ULONG BufferLength);
41 typedef NTSTATUS(*HidP_GetCaps_Type)(PHIDP_PREPARSED_DATA PreparsedData, PHIDP_CAPS Capabilities);
42 typedef NTSTATUS(*HidP_GetButtonCaps_Type)(HIDP_REPORT_TYPE ReportType, PHIDP_BUTTON_CAPS ButtonCaps, PUSHORT ButtonCapsLength, PHIDP_PREPARSED_DATA PreparsedData);
43 typedef NTSTATUS(*HidP_GetValueCaps_Type)(HIDP_REPORT_TYPE ReportType, PHIDP_VALUE_CAPS ValueCaps, PUSHORT ValueCapsLength, PHIDP_PREPARSED_DATA PreparsedData);
44 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);
45 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);
46 typedef NTSTATUS(*HidP_GetData_Type)(HIDP_REPORT_TYPE ReportType, PHIDP_DATA DataList, PULONG DataLength, PHIDP_PREPARSED_DATA PreparsedData, PCHAR Report, ULONG ReportLength);
51 HANDLE DllHandle =
nullptr;
53 HidD_GetSerialNumberString_Type HidD_GetSerialNumberString;
54 HidD_GetManufacturerString_Type HidD_GetManufacturerString;
55 HidD_GetProductString_Type HidD_GetProductString;
56 HidP_GetCaps_Type HidP_GetCaps;
57 HidP_GetButtonCaps_Type HidP_GetButtonCaps;
58 HidP_GetValueCaps_Type HidP_GetValueCaps;
59 HidP_GetUsages_Type HidP_GetUsages;
60 HidP_GetUsageValue_Type HidP_GetUsageValue;
61 HidP_GetData_Type HidP_GetData;
139struct FHidPov : FHidAxis
189 UserId(PLATFORMUSERID_NONE),
246class FEnhancedRawInputWindows :
public IEnhancedRawInput, IWindowsMessageHandler
248 friend class UEnhancedRawInputSettings;
251 FEnhancedRawInputWindows(
const TSharedRef<FGenericApplicationMessageHandler>& InMessageHandler);
252 virtual ~FEnhancedRawInputWindows()
override;
255 virtual void SetBindings(
const FString InterfaceName)
override;
256 virtual void SetAxisBinding(
const FString InterfaceName,
const int32 AxisUsage,
const FName KeyName)
override;
257 virtual void SetButtonBinding(
const FString InterfaceName,
const int32 ButtonIndex,
const FName KeyName)
override;
258 virtual void SetPovAxisBinding(
const FString InterfaceName,
const int32 PovIndex, FName KeyName)
override;
259 virtual void SetPovButtonBinding(
const FString InterfaceName,
const int32 PovIndex, TArray<FName> KeyNames)
override;
263 virtual void SetChannelValue(int32 ControllerId, FForceFeedbackChannelType ChannelType,
float Value)
override {}
264 virtual void SetChannelValues(int32 ControllerId,
const FForceFeedbackValues &Values)
override {}
265 virtual bool Exec(UWorld* InWorld,
const TCHAR* Cmd, FOutputDevice& Ar)
override {
return false; }
266 virtual void SetMessageHandler(
const TSharedRef<FGenericApplicationMessageHandler> &InMessageHandler)
override;
267 virtual void Tick(
float DeltaTime)
override;
268 virtual void SendControllerEvents()
override;
269 virtual bool SupportsForceFeedback(int32 ControllerId)
override {
return false; }
273 virtual bool ProcessMessage(HWND Hwnd, uint32 Msg, WPARAM WParam, LPARAM LParam, int32& OutResult)
override;
296 TMap<int32, FHidAxis>
GetAxisInfo(
const FString& InterfaceName);
301 TArray<FHidPov>
GetPovInfo(
const FString& InterfaceName);
321 typedef CONFIGRET(*CM_Register_Notification_Type)(PCM_NOTIFY_FILTER pFilter, PVOID pContext, PCM_NOTIFY_CALLBACK pCallback, PHCMNOTIFICATION pNotifyContext);
323 CM_Register_Notification_Type CmRegisterNotification;
324 HANDLE Cfgmgr32DllHandle =
nullptr;
325 HCMNOTIFICATION NotifyContext;
327 bool bRefreshDevices =
false;
328 FDateTime DeviceRefreshStart;
330 bool bDeviceRegistered =
false;
333 TArray<FString> ActualConnectedDevices;
336 void QueryDeviceCaps(
FHidDevice &Device)
const;
338 FHidDevice *FindDeviceByHandle(HANDLE Handle);
340 void ShowDebug(AHUD* HUD, UCanvas* Canvas,
const FDebugDisplayInfo& DisplayInfo,
float& YL,
float& YPos);
342 static bool TryRegisterInputDevice();
float Offset
Axis offset as configured.
Definition EnhancedRawInputWindows.h:98
int32 Max
Maximal value, as reported from the driver.
Definition EnhancedRawInputWindows.h:95
FName KeyName
Bound Key name.
Definition EnhancedRawInputWindows.h:83
int32 Min
Minimal value, as reported from the driver.
Definition EnhancedRawInputWindows.h:92
ERawInputAxisOutputType OutputType
Configured output type.
Definition EnhancedRawInputWindows.h:89
bool bIsInverted
Whether is axis inverted (from Configuration)
Definition EnhancedRawInputWindows.h:101
float GetValue() const
Value of this axis, normalised, inverted and/or in specific format, according to configuration.
Definition EnhancedRawInputWindows.cpp:50
bool bIsEnabled
TRUE if axis is enabled in settings.
Definition EnhancedRawInputWindows.h:86
bool HasValue() const
Whether this axis has valid value.
Definition EnhancedRawInputWindows.cpp:74
bool bHasChanged
Whether value has changed since last HID event.
Definition EnhancedRawInputWindows.h:104
int32 Value
Current value of this axis.
Definition EnhancedRawInputWindows.h:80
Stores information and data about a HID Device.
Definition EnhancedRawInputWindows.h:182
uint32 ButtonUsageMin
Internally used.
Definition EnhancedRawInputWindows.h:221
int32 ControllerId
Internal unique controller ID.
Definition EnhancedRawInputWindows.h:203
FPlatformUserId UserId
Current User ID for this device, as reported from Unreal engine.
Definition EnhancedRawInputWindows.h:224
bool bIsActive
Whether the device is active and being handled.
Definition EnhancedRawInputWindows.h:230
EInputDeviceConnectionState ConnectionState
Connection state for this device.
Definition EnhancedRawInputWindows.h:233
FInputDeviceId DeviceId
Current Device ID for this device, as reported from Unreal engine.
Definition EnhancedRawInputWindows.h:227
FString InterfaceName
Interface name as reported from driver.
Definition EnhancedRawInputWindows.h:209
FString SerialNumber
Serial number as reported from driver, may be empty.
Definition EnhancedRawInputWindows.h:215
TArray< FHidPov > PoVs
Information about all PoVs for this device.
Definition EnhancedRawInputWindows.h:242
TArray< FHidButton > Buttons
Information about all buttons for this device.
Definition EnhancedRawInputWindows.h:236
int32 NumberInputValueCaps
Number of HID Value (Axis) capability's, internally used.
Definition EnhancedRawInputWindows.h:206
HANDLE Handle
Internal HID Handle.
Definition EnhancedRawInputWindows.h:197
FString ProductName
Product name as reported from driver, may be empty.
Definition EnhancedRawInputWindows.h:218
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:200
TMap< int32, FHidAxis > Axis
Information about all axis for this device.
Definition EnhancedRawInputWindows.h:239
FString Manufacturer
Manufacturer name as reported from driver, may be empty.
Definition EnhancedRawInputWindows.h:212
bool HasAxisValue() const
Checks if axis is configured and has valid value.
Definition EnhancedRawInputWindows.cpp:157
ERawInputPovOutputType PovOutputType
Output type as configured.
Definition EnhancedRawInputWindows.h:157
float GetAxisValue() const
Returns (normalised, depends on output type) value.
Definition EnhancedRawInputWindows.cpp:121
TArray< bool > ButtonStates
Sates of the virtual D-Pad Buttons.
Definition EnhancedRawInputWindows.h:151
void UpdateButtonValues()
Updates the virtual D-PAD buttons, internally used.
Definition EnhancedRawInputWindows.cpp:92
uint16 DataIndex
Data index, internally used.
Definition EnhancedRawInputWindows.h:148
int32 GetPovValueDeg() const
Get Value of this POV.
Definition EnhancedRawInputWindows.cpp:81
bool HasButtonValue(uint32 Index) const
Checks if a button is configured and has valid value.
Definition EnhancedRawInputWindows.cpp:152
TArray< FName > ButtonKeyNames
Keynames as configured.
Definition EnhancedRawInputWindows.h:154
Internal structure for function pointers to Windows APIs. Not for public use.
Definition EnhancedRawInputWindows.h:36