예제 #1
0
        public unsafe override bool SetEnableAutocenter(bool enable)
        {
            IDirectInputDevice8 *directInputDevice =
                ((DirectInputJoystickInputDevice)Device).directInputDevice;

            DIPROPDWORD dipdw = new DIPROPDWORD();

            dipdw.diph.dwSize       = (uint)sizeof(DIPROPDWORD);
            dipdw.diph.dwHeaderSize = (uint)sizeof(DIPROPHEADER);
            dipdw.diph.dwObj        = 0;
            dipdw.diph.dwHow        = DInput.DIPH_DEVICE;
            dipdw.dwData            = (uint)((enable) ? 1 : 0);

            GUID *centerProp = (GUID *)DInput.getDIPROP_AUTOCENTER();
            int   hr         = IDirectInputDevice8.SetProperty(directInputDevice, centerProp, ref dipdw.diph);

            if (Wrapper.FAILED(hr))
            {
                Log.Warning("DirectInputForceFeedbackController: " +
                            "Cannot change autocenter property for \"{0}\".", Device.Name);
                return(false);
            }

            return(true);
        }
예제 #2
0
        unsafe bool InitInternal(IntPtr windowHandle, IDirectInput *alreadyCreatedDirectInput)
        {
            int hr;

            if (alreadyCreatedDirectInput == null)
            {
                void */*IDirectInput*/ directInputTemp;

                GUID iidDIrectInput = DInput.IID_IDirectInput8W;
                hr = DInput.DirectInput8Create(ref iidDIrectInput, out directInputTemp);
                if (DirectInput.Wrapper.FAILED(hr))
                {
                    Log.Info("SystemMouseDevice: DirectInput: DirectInput8Create failed.");
                    return(false);
                }

                directInput            = (IDirectInput *)directInputTemp;
                needReleaseDirectInput = true;
            }
            else
            {
                directInput = alreadyCreatedDirectInput;
            }

            void */*IDirectInputDevice8*/ mouseDeviceTemp;
            GUID guidSysMouse = DInput.GUID_SysMouse;

            hr = IDirectInput.CreateDevice(directInput, ref guidSysMouse,
                                           out mouseDeviceTemp, null);

            if (Wrapper.FAILED(hr))
            {
                Log.Info("SystemMouseDevice: DirectInput: CreateDevice failed.");
                return(false);
            }
            mouseDevice = (IDirectInputDevice8 *)mouseDeviceTemp;

            hr = IDirectInputDevice8.SetDataFormat(mouseDevice, DInput.Get_c_dfDIMouse());
            if (Wrapper.FAILED(hr))
            {
                Log.Info("SystemMouseDevice: DirectInput: SetDataFormat failed.");
                return(false);
            }

            //!!!!для Game.exe включать
            //if( windowHandle != IntPtr.Zero )
            //	Acquire( windowHandle );

            return(true);
        }
예제 #3
0
        public unsafe DirectInputForceFeedbackController(IDirectInputDevice8 *directInputDevice,
                                                         JoystickInputDevice joystick)
            : base(joystick)
        {
            int hr = IDirectInputDevice8.EnumEffects(directInputDevice, EnumEffectHandler, null,
                                                     DInput.DIEFT_ALL);

            if (Wrapper.FAILED(hr))
            {
                Log.Warning("DirectInputForceFeedbackController: " +
                            "Cannot enum ForceFeedbackEffects for \"{0}\" ({1}).", Device.Name,
                            DInput.GetOutString(DInput.DXGetErrorStringW(hr)));
            }
        }
        protected unsafe override void OnShutdown()
        {
            if (directInputDevice != null)
            {
                IDirectInputDevice8.Unacquire(directInputDevice);
                IDirectInputDevice8.Release(directInputDevice);
                directInputDevice = null;
            }

            if (deviceDataBuffer != IntPtr.Zero)
            {
                NativeUtility.Free(deviceDataBuffer);
                deviceDataBuffer = IntPtr.Zero;
            }
        }
예제 #5
0
        unsafe void ShutdownInternal()
        {
            if (mouseDevice != null)
            {
                Unacquire();
                IDirectInputDevice8.Release(mouseDevice);
                mouseDevice = null;
            }

            if (directInput != null)
            {
                if (needReleaseDirectInput)
                {
                    IDirectInput.Release(directInput);
                }
                directInput = null;
            }
        }
        internal unsafe bool Init()
        {
            GUID devGuid = deviceGuid;

            void */*IDirectInputDevice8*/ directInputDeviceTemp = null;

            int hr = IDirectInput.CreateDevice(
                WindowsInputDeviceManager.Instance.DirectInput,
                ref devGuid, out directInputDeviceTemp, null);

            if (Wrapper.FAILED(hr))
            {
                Log.Warning("DirectInputJoystickDevice: Cannot create device \"{0}\" ({1}).",
                            Name, DInput.GetOutString(DInput.DXGetErrorStringW(hr)));
                return(false);
            }

            directInputDevice = (IDirectInputDevice8 *)directInputDeviceTemp;

            // get capabilities

            DIDEVCAPS caps = new DIDEVCAPS();

            caps.dwSize = (uint)sizeof(DIDEVCAPS);

            hr = IDirectInputDevice8.GetCapabilities(directInputDevice, ref caps);
            if (Wrapper.FAILED(hr))
            {
                Log.Warning("DirectInputJoystickDevice: Cannot get device capabilities \"{0}\".", Name);
                return(false);
            }

            //buttons
            Button[] buttons = new Button[caps.dwButtons];
            for (int n = 0; n < buttons.Length; n++)
            {
                buttons[n] = new Button((JoystickButtons)n, n);
            }

            //povs
            POV[] povs = new POV[caps.dwPOVs];
            for (int n = 0; n < povs.Length; n++)
            {
                povs[n] = new JoystickInputDevice.POV((JoystickPOVs)n);
            }

            // setup

            hr = IDirectInputDevice8.SetDataFormat(directInputDevice, DInput.Get_c_dfDIJoystick2());

            if (Wrapper.FAILED(hr))
            {
                Log.Warning("DirectInputJoystickDevice: Cannot set device data format \"{0}\".", Name);
                return(false);
            }

            hr = IDirectInputDevice8.SetCooperativeLevel(directInputDevice,
                                                         WindowsInputDeviceManager.Instance.WindowHandle,
                                                         DInput.DISCL_EXCLUSIVE | DInput.DISCL_FOREGROUND);

            if (Wrapper.FAILED(hr))
            {
                Log.Warning("DirectInputJoystickDevice: Cannot set device " +
                            "cooperative level \"{0}\".", Name);
                return(false);
            }

            //-------------------------------------------------------------------
            // setup size for buffered input

            DIPROPDWORD dibuf = new DIPROPDWORD();

            dibuf.diph.dwSize       = (uint)sizeof(DIPROPDWORD);
            dibuf.diph.dwHeaderSize = (uint)sizeof(DIPROPHEADER);
            dibuf.diph.dwHow        = DInput.DIPH_DEVICE;
            dibuf.diph.dwObj        = 0;
            dibuf.dwData            = BufferSize;

            GUID *bufferSizeGuid = (GUID *)DInput.getDIPROP_BUFFERSIZE();

            hr = IDirectInputDevice8.SetProperty(directInputDevice, bufferSizeGuid, ref dibuf.diph);
            if (Wrapper.FAILED(hr))
            {
                Log.Warning("DirectInputJoystickDevice: Cannot set device buffer size \"{0}\".",
                            Name);
                return(false);
            }

            deviceDataBuffer = NativeUtility.Alloc(NativeUtility.MemoryAllocationType.Utility,
                                                   sizeof(DIDEVICEOBJECTDATA) * BufferSize);

            //--------------------------------------------------------------------

            temporarySliderCount = 0;

            temporaryAxisList = new List <JoystickInputDevice.Axis>();

            tempDeviceForEnumerate = this;
            hr = IDirectInputDevice8.EnumObjects(directInputDevice, EnumDeviceObjectsHandler,
                                                 null, DInput.DIDFT_ALL);
            tempDeviceForEnumerate = null;

            if (Wrapper.FAILED(hr))
            {
                Log.Warning("DirectInputJoystickDevice: Cannot enumerate device objects \"{0}\".",
                            Name);
                return(false);
            }

            //axes
            Axis[] axes = temporaryAxisList.ToArray();
            temporaryAxisList = null;

            //sliders
            Slider[] sliders = new Slider[temporarySliderCount];
            for (int n = 0; n < sliders.Length; n++)
            {
                sliders[n] = new JoystickInputDevice.Slider((JoystickSliders)n);
            }

            //forceFeedbackController
            ForceFeedbackController forceFeedbackController = null;

            if ((caps.dwFlags & DInput.DIDC_FORCEFEEDBACK) != 0)
            {
                forceFeedbackController = new DirectInputForceFeedbackController(directInputDevice, this);
            }

            //initialize data
            InitDeviceData(buttons, axes, povs, sliders, forceFeedbackController);

            return(true);
        }