public static void OnDeviceStateChange(object sender, EventArgs args)
    {
        DIJOYSTATE2State state = DirectInputFFB.Utilities.UnFlatJoyState2(DirectInputFFB.FFBManager.state);

        // Check if DirectInputDevice is enabled
        if (InputSystem.devices.FirstOrDefault(x => x is DirectInputDevice) != null)
        {
            InputSystem.QueueStateEvent(DirectInputDevice.current, state);   // Only bubble Input System Event if input has changed
        }
    }
        public static DIJOYSTATE2State UnFlatJoyState2(FlatJoyState2 state)
        {
            DIJOYSTATE2State DIJ2S = new DIJOYSTATE2State();

            DIJ2S.buttonsA = state.buttonsA; // Buttons seperated into banks of 64-Bits to fit into Unsigned 64-bit integer
            DIJ2S.buttonsB = state.buttonsB; // Buttons seperated into banks of 64-Bits to fit into Unsigned 64-bit integer
            DIJ2S.lX       = state.lX;       // X-axis
            DIJ2S.lY       = state.lY;       // Y-axis
            DIJ2S.lZ       = state.lZ;       // Z-axis
            DIJ2S.lU       = state.lU;       // U-axis
            DIJ2S.lV       = state.lV;       // V-axis
            DIJ2S.lRx      = state.lRx;      // X-axis rotation
            DIJ2S.lRy      = state.lRy;      // Y-axis rotation
            DIJ2S.lRz      = state.lRz;      // Z-axis rotation
            DIJ2S.lVX      = state.lVX;      // X-axis velocity
            DIJ2S.lVY      = state.lVY;      // Y-axis velocity
            DIJ2S.lVZ      = state.lVZ;      // Z-axis velocity
            DIJ2S.lVU      = state.lVU;      // U-axis velocity
            DIJ2S.lVV      = state.lVV;      // V-axis velocity
            DIJ2S.lVRx     = state.lVRx;     // X-axis angular velocity
            DIJ2S.lVRy     = state.lVRy;     // Y-axis angular velocity
            DIJ2S.lVRz     = state.lVRz;     // Z-axis angular velocity
            DIJ2S.lAX      = state.lAX;      // X-axis acceleration
            DIJ2S.lAY      = state.lAY;      // Y-axis acceleration
            DIJ2S.lAZ      = state.lAZ;      // Z-axis acceleration
            DIJ2S.lAU      = state.lAU;      // U-axis acceleration
            DIJ2S.lAV      = state.lAV;      // V-axis acceleration
            DIJ2S.lARx     = state.lARx;     // X-axis angular acceleration
            DIJ2S.lARy     = state.lARy;     // Y-axis angular acceleration
            DIJ2S.lARz     = state.lARz;     // Z-axis angular acceleration
            DIJ2S.lFX      = state.lFX;      // X-axis force
            DIJ2S.lFY      = state.lFY;      // Y-axis force
            DIJ2S.lFZ      = state.lFZ;      // Z-axis force
            DIJ2S.lFU      = state.lFU;      // U-axis force
            DIJ2S.lFV      = state.lFV;      // V-axis force
            DIJ2S.lFRx     = state.lFRx;     // X-axis torque
            DIJ2S.lFRy     = state.lFRy;     // Y-axis torque
            DIJ2S.lFRz     = state.lFRz;     // Z-axis torque
            DIJ2S.rgdwPOV  = state.rgdwPOV;  // Store each DPAD in chunks of 4 bits inside 16-bit short
            return(DIJ2S);
        }