// UE/InputDeviceSubsystem.ts import { EHardwareDevicePrimaryType } from '#root/UE/EHardwareDevicePrimaryType.ts'; import { EngineSubsystem } from '#root/UE/EngineSubsystem.ts'; import { HardwareDeviceIdentifier } from '#root/UE/HardwareDeviceIdentifier.ts'; import type { Integer } from '#root/UE/Integer.ts'; import { Name } from '#root/UE/Name.ts'; import { UEObject } from '#root/UE/UEObject.ts'; class InputDeviceSubsystemClass extends EngineSubsystem { private readonly currentDevice: HardwareDeviceIdentifier; private readonly registeredCallbacks: (( UserId: Integer, DeviceId: Integer ) => void)[] = []; constructor(outer: UEObject | null = null, name: Name | string = Name.NONE) { super(outer, name); // Initialize with default keyboard/mouse this.currentDevice = new HardwareDeviceIdentifier( new Name('EnhancedInput'), new Name('KeyboardMouse'), EHardwareDevicePrimaryType.KeyboardAndMouse, 0xff // Full feature support mask ); } /** * Get the most recently used hardware device * This is the primary API for device detection in Unreal Engine * @returns Hardware device identifier structure */ public GetMostRecentlyUsedHardwareDevice(): HardwareDeviceIdentifier { return this.currentDevice; } /** * Get hardware device identifier by device ID * @param DeviceId - Device ID to look up * @returns Hardware device identifier structure */ public GetInputDeviceHardwareIdentifier( DeviceId: Integer ): HardwareDeviceIdentifier { // In a real implementation, this would look up the device by ID // Here we just return the current device for demonstration purposes console.log(DeviceId); return this.currentDevice; } /** * Event fired when input hardware device changes * This is the main delegate for device detection in UE 5.3+ */ public OnInputHardwareDeviceChanged = { BindEvent: ( callback: (UserId: Integer, DeviceId: Integer) => void ): void => { this.registeredCallbacks.push(callback); console.log( 'Device change delegate bound, total callbacks:', this.registeredCallbacks.length ); }, UnbindEvent: ( callback: (UserId: Integer, DeviceId: Integer) => void ): void => { const index = this.registeredCallbacks.indexOf(callback); if (index !== -1) { this.registeredCallbacks.splice(index, 1); console.log( 'Device change delegate unbound, remaining callbacks:', this.registeredCallbacks.length ); } }, UnbindAllEvents: (): void => { const previousCount = this.registeredCallbacks.length; this.registeredCallbacks.length = 0; // Clear array console.log( `All device change delegates unbound. Removed ${previousCount} callbacks.` ); }, }; } export const InputDeviceSubsystem = new InputDeviceSubsystemClass();