Exemple #1
0
    public DIInputDevice()
    {
        _directInput = DInput.DirectInput8Create();

        _keyboardDevices = new Dictionary <Guid, IDirectInputDevice8>();
        _joystickDevices = new Dictionary <Guid, IDirectInputDevice8>();
    }
Exemple #2
0
    public static Result DirectInput8Create(out IDirectInput8?directInput)
    {
        Result result = DirectInput8Create(GetModuleHandle(null), SdkVersion, typeof(IDirectInput8).GUID, out IntPtr nativePtr, null);

        if (result.Failure)
        {
            directInput = default;
            return(result);
        }

        directInput = new IDirectInput8(nativePtr);
        return(result);
    }
Exemple #3
0
    static public Dictionary <Guid, DeviceInstance> EnumerateAllAttachedGameDevices(IDirectInput8 directInput)
    {
        Dictionary <Guid, DeviceInstance> connectedDeviceList_ = new Dictionary <Guid, DeviceInstance>();

        foreach (DeviceInstance deviceInstance_ in directInput.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly))
        {
            if (deviceInstance_.Type == Vortice.DirectInput.DeviceType.Gamepad || deviceInstance_.Type == Vortice.DirectInput.DeviceType.Joystick)
            {
                connectedDeviceList_.Add(deviceInstance_.InstanceGuid, deviceInstance_);
            }
            else
            {
                Console.WriteLine(deviceInstance_.ProductName + " does not match input type, ignored.");
            }
        }

        return(connectedDeviceList_);
    }
Exemple #4
0
    private void InitializeJoystickDevice(IDirectInput8 directInput, Guid guid, IntPtr windowhandle)
    {
        IDirectInputDevice8 inputDevice = directInput.CreateDevice(guid);

        inputDevice.SetCooperativeLevel(windowhandle, CooperativeLevel.NonExclusive | CooperativeLevel.Foreground);

        // Play the values back to see that buffersize is working correctly
        inputDevice.Properties.BufferSize = 16;

        if (directInput.IsDeviceAttached(guid))
        {
            Result result = inputDevice.SetDataFormat <RawJoystickState>();

            if (result.Success)
            {
                _joystickDevices.Add(guid, inputDevice);
            }
        }
    }
        void InitialiseKeyboardDevice(IDirectInput8 directInput, Guid guid, IntPtr windowhandle)
        {
            IDirectInputDevice8 inputDevice_ = directInput.CreateDevice(guid);

            Result result_ = inputDevice_.SetCooperativeLevel(windowhandle, CooperativeLevel.NonExclusive | CooperativeLevel.Foreground);

            // play the values back to see that buffersize is working correctly
            inputDevice_.Properties.BufferSize = 16;

            int size = inputDevice_.Properties.BufferSize;

            if (directInput.IsDeviceAttached(guid))
            {
                result_ = inputDevice_.SetDataFormat <RawKeyboardState>();

                if (result_.Success)
                {
                    _keyboardDevices.Add(guid, inputDevice_);
                }
            }
        }
Exemple #6
0
    public static Dictionary <Guid, DeviceInstance> EnumerateAllAttachedKeyboardDevices(IDirectInput8 directInput)
    {
        Dictionary <Guid, DeviceInstance> result = new();

        foreach (DeviceInstance deviceInstance in directInput.GetDevices(DeviceClass.Keyboard, DeviceEnumerationFlags.AttachedOnly))
        {
            if (deviceInstance.Type == DeviceType.Keyboard)
            {
                result.Add(deviceInstance.InstanceGuid, deviceInstance);
            }
            else
            {
                Console.WriteLine(deviceInstance.ProductName + " does not match input type, ignored.");
            }
        }

        return(result);
    }