示例#1
0
        public InputOperator(System.Windows.Forms.Control pmTargetControl)
        {
            DirectInput dinput = new DirectInput();

            this.mainKB = new Keyboard(dinput);
            CooperativeLevel cl = CooperativeLevel.Exclusive;

            cl |= CooperativeLevel.Foreground;
            cl |= CooperativeLevel.NoWinKey;
            this.mainKB.SetCooperativeLevel(pmTargetControl, cl);
            mainKB.Properties.BufferSize = 8;
            mainKB.Acquire();
        }
示例#2
0
        public KeyboardCapture(IntPtr handle)
        {
            DirectInput      directInput = new DirectInput();
            CooperativeLevel flags       = CooperativeLevel.NoWinKey | CooperativeLevel.Foreground | CooperativeLevel.Exclusive;

            try {
                keyboard = new Keyboard(directInput);
                keyboard.SetCooperativeLevel(handle, flags);
            } catch (DirectInputException ex) {
                int num = (int)MessageBox.Show("DirectInput Error " + ex.Message);
                return;
            }
            keyboard.Acquire();
        }
示例#3
0
        public DxDeviceContext(IntPtr formHandle, Control renderAreaObject, bool fullscreen)
        {
            _isFullscreen = fullscreen;

            SwapChainDescription desc = new SwapChainDescription();

            if (fullscreen)
            {
                throw new ApplicationException("Not implemented yet");
            }
            else
            {
                FrameWidth  = renderAreaObject.Width;
                FrameHeight = renderAreaObject.Height;

                desc.BufferCount     = 1;
                desc.ModeDescription = new ModeDescription(FrameWidth,
                                                           FrameHeight,
                                                           new SlimDX.Rational(60, 1),
                                                           Format.R8G8B8A8_UNorm);
                desc.IsWindowed = true;
                desc.SwapEffect = SwapEffect.Discard;
            }

            desc.OutputHandle      = renderAreaObject.Handle;
            desc.SampleDescription = new SampleDescription(1, 0);
            desc.Usage             = Usage.RenderTargetOutput;

            Device    dev;
            SwapChain swapChain;

            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, desc, out dev, out swapChain);
            Device    = dev;
            SwapChain = swapChain;
            Device.Factory.SetWindowAssociation(renderAreaObject.Handle, WindowAssociationFlags.IgnoreAll);

            _dInput = new DirectInput();
            CooperativeLevel cooLevel = CooperativeLevel.Foreground;

            cooLevel |= CooperativeLevel.Nonexclusive;
            _mouse    = new Mouse(_dInput);
            _mouse.SetCooperativeLevel(formHandle, cooLevel);

            _shaderByteCode = ShaderBytecode.CompileFromFile(GetFxFile(), "fx_5_0", ShaderFlags.None, EffectFlags.None);
            Effect          = new SlimDX.Direct3D11.Effect(Device, _shaderByteCode);
        }
示例#4
0
        public static void CreateDevice(IntPtr hwnd)
        {
            dinput = new DirectInput();
            CooperativeLevel cooperativeLevel = CooperativeLevel.Nonexclusive | CooperativeLevel.Background;

            try
            {
                mouseDevice = new Mouse(dinput);
                mouseDevice.SetCooperativeLevel(hwnd, cooperativeLevel);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            mouseDevice.Acquire();
        }
        public DirectInputManager()
        {
            var directInput = new DirectInput();

            // Prefer a Driving device but make do with fallback to a Joystick if we have to
            var deviceInstance = FindAttachedDevice(directInput, DeviceType.Driving);

            if (null == deviceInstance)
            {
                deviceInstance = FindAttachedDevice(directInput, DeviceType.Joystick);
            }
            if (null == deviceInstance)
            {
                throw new Exception("No Driving or Joystick devices attached.");
            }
            joystickType = (DeviceType.Driving == deviceInstance.Type ? JoystickTypes.Driving : JoystickTypes.Joystick);

            // A little debug spew is often good for you
            Log.Spew("First Suitable Device Selected \"" + deviceInstance.InstanceName + "\":");
            Log.Spew("\tProductName: " + deviceInstance.ProductName);
            Log.Spew("\tType: " + deviceInstance.Type);
            Log.Spew("\tSubType: " + deviceInstance.Subtype);

            // Data for both Driving and Joystick device types is received via Joystick
            joystick = new Joystick(directInput, deviceInstance.InstanceGuid);
            IntPtr consoleWindowHandle = GetConsoleWindow();

            if (IntPtr.Zero != consoleWindowHandle)
            {
                CooperativeLevel cooperativeLevel = CooperativeLevel.Background | CooperativeLevel.Nonexclusive;
                Log.Spew("Console window cooperative level: " + cooperativeLevel);
                if (!joystick.SetCooperativeLevel(consoleWindowHandle, cooperativeLevel).IsSuccess)
                {
                    throw new Exception("Failed to set cooperative level for DirectInput device in console window.");
                }
            }
            var result = joystick.Acquire();

            if (!result.IsSuccess)
            {
                throw new Exception("Failed to acquire DirectInput device.");
            }

            Log.Spew("Joystick acquired.");
        }
        public DirectXKeyboard(InputManager creator, DirectInput directInput, bool buffered, CooperativeLevel coopSettings)
        {
            Creator            = creator;
            this._directInput  = directInput;
            IsBuffered         = buffered;
            this._coopSettings = coopSettings;
            Type          = InputType.Keyboard;
            EventListener = null;

            this._kbInfo = (KeyboardInfo)((DirectXInputManager)Creator).CaptureDevice <Keyboard>();

            if (this._kbInfo == null)
            {
                throw new Exception("No devices match requested type.");
            }

            log.Debug("DirectXKeyboard device created.");
        }
示例#7
0
        public static void CreateDevice(IntPtr handle)
        {
            dinput = new DirectInput();
            CooperativeLevel cooperativeLevel = CooperativeLevel.Nonexclusive | CooperativeLevel.Background;

            try
            {
                keyboardDevice = new Keyboard(dinput);
                keyboardDevice.SetCooperativeLevel(handle, cooperativeLevel);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            // since we want to use buffered data, we need to tell DirectInput
            // to set up a buffer for the data
            //keyboardDevice.Properties.BufferSize = 8;

            // acquire the device
            keyboardDevice.Acquire();
        }
示例#8
0
        public static void CreateDevice(System.Windows.Forms.Form gw)
        {
            dinput = new DirectInput();
            CooperativeLevel cooperativeLevel = CooperativeLevel.Exclusive | CooperativeLevel.Foreground;

            try
            {
                mouseDevice = new Mouse(dinput);
                mouseDevice.SetCooperativeLevel(gw, cooperativeLevel);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            // since we want to use buffered data, we need to tell DirectInput
            // to set up a buffer for the data
            //keyboardDevice.Properties.BufferSize = 8;

            // acquire the device
            mouseDevice.Acquire();
        }
示例#9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:SharpDX.DirectSound.FullDuplex" /> class.
 /// </summary>
 /// <param name="captureDevice" />
 /// <param name="playbackDevice" />
 /// <param name="captureDescription" />
 /// <param name="bufferDescription" />
 /// <param name="windowHandle" />
 /// <param name="level" />
 /// <param name="captureBuffer" />
 /// <param name="secondaryBuffer" />
 public FullDuplex(Guid captureDevice, Guid playbackDevice, CaptureBufferDescription captureDescription, SoundBufferDescription bufferDescription, IntPtr windowHandle, CooperativeLevel level, out CaptureBuffer captureBuffer, out SecondarySoundBuffer secondaryBuffer)
 {
     DSound.FullDuplexCreate(captureDevice, playbackDevice, captureDescription, bufferDescription, windowHandle, (int)level, this,
                             out captureBuffer, out secondaryBuffer, null);
 }
示例#10
0
        // Disabled as it seems to be not used anymore
        ///// <summary>
        ///// Sends data to a device that accepts output. Applications should not use this method. Force Feedback is the recommended way to send data to a device. If you want to send other data to a device, such as changing LED or internal device states, the HID application programming interface (API) is the recommended way.
        ///// </summary>
        ///// <param name="data">An array of object data.</param>
        ///// <param name="overlay">if set to <c>true</c> the device data sent is overlaid on the previously sent device data..</param>
        ///// <returns>A <see cref = "T:SharpDX.Result" /> object describing the result of the operation.</returns>
        //public Result SendData(ObjectData[] data, bool overlay)
        //{
        //    unsafe
        //    {
        //        int count = data==null?0:data.Length;
        //        return SendDeviceData(sizeof (ObjectData), data, ref count, overlay ? 1 : 0);
        //    }
        //}

        /// <summary>
        /// Requests the cooperative level for this instance of the input device. The cooperative level determines how this instance of the device interacts with other instances of the device and the rest of the system.
        /// </summary>
        /// <param name="control">Window control to be associated with the device. This parameter must be a valid top-level window handle that belongs to the process. The window associated with the device must not be destroyed while it is still active in a DirectInput device.</param>
        /// <param name="level">Flags that specify the cooperative level to associate with the input device.</param>
        /// <returns>If the method succeeds, the return value is <see cref="SharpDX.DirectInput.ResultCode.Ok"/>. If the method fails, a <see cref="SharpDXException"/> is raised with the following error code values: <see cref="SharpDX.DirectInput.ResultCode.InvalidParam"/>, <see cref="SharpDX.DirectInput.ResultCode.NotInitialized"/>, <see cref="Result.Handle"/>.</returns>
        /// <remarks>
        /// <para>Applications cannot specify <see cref="SharpDX.DirectInput.CooperativeLevel.Foreground"/> and <see cref="SharpDX.DirectInput.CooperativeLevel.Background"/> at the same time. This apply as well to <see cref="SharpDX.DirectInput.CooperativeLevel.Exclusive"/> and <see cref="SharpDX.DirectInput.CooperativeLevel.NonExclusive"/>.</para>
        ///  <para>When the mouse is acquired with exclusive access, the mouse pointer is removed from the screen until the device is unacquired.</para>
        ///  <para>Applications that select the background exclusive mode cooperative level are not guaranteed to retain access to the device if another application requests exclusive access. When a background exclusive mode application loses access, calls to DirectInput device methods will fail and return <see cref="SharpDX.DirectInput.ResultCode.NotAcquired"/>. The application can regain access to the device by manually unacquiring the device and reacquiring it.</para>
        ///  <para>Applications must call this method before acquiring the device by using the <see cref="SharpDX.DirectInput.Device"/> method.</para>
        /// </remarks>
        /// <unmanaged>HRESULT IDirectInputDevice8W::SetCooperativeLevel([In] HWND arg0,[In] DISCL arg1)</unmanaged>
        public void SetCooperativeLevel(Control control, CooperativeLevel level)
        {
            SetCooperativeLevel(control.Handle, level);
        }
示例#11
0
 public void init(Control c, CooperativeLevel level)
 {
     dic.Clear();
     device.SetCooperativeLevel(c, level);
 }
示例#12
0
文件: Device.cs 项目: Ziriax/SharpDX
        // Disabled as it seems to be not used anymore
        ///// <summary>
        ///// Sends data to a device that accepts output. Applications should not use this method. Force Feedback is the recommended way to send data to a device. If you want to send other data to a device, such as changing LED or internal device states, the HID application programming interface (API) is the recommended way.
        ///// </summary>
        ///// <param name="data">An array of object data.</param>
        ///// <param name="overlay">if set to <c>true</c> the device data sent is overlaid on the previously sent device data..</param>
        ///// <returns>A <see cref = "T:SharpDX.Result" /> object describing the result of the operation.</returns>
        //public Result SendData(ObjectData[] data, bool overlay)
        //{
        //    unsafe
        //    {
        //        int count = data==null?0:data.Length;
        //        return SendDeviceData(sizeof (ObjectData), data, ref count, overlay ? 1 : 0);
        //    }
        //}

        /// <summary>	
        /// Requests the cooperative level for this instance of the inpute device. The cooperative level determines how this instance of the device interacts with other instances of the device and the rest of the system.	
        /// </summary>	
        /// <param name="control">Window control to be associated with the device. This parameter must be a valid top-level window handle that belongs to the process. The window associated with the device must not be destroyed while it is still active in a DirectInput device.</param>	
        /// <param name="level">Flags that specify the cooperative level to associate with the input device.</param>	
        /// <returns>If the method succeeds, the return value is <see cref="SharpDX.DirectInput.ResultCode.Ok"/>. If the method fails, a <see cref="SharpDXException"/> is raised with the following error code values: <see cref="SharpDX.DirectInput.ResultCode.InvalidParam"/>, <see cref="SharpDX.DirectInput.ResultCode.NotInitialized"/>, <see cref="Result.Handle"/>.</returns>	
        /// <remarks>	
        /// <para>Applications cannot specify <see cref="SharpDX.DirectInput.CooperativeLevel.Foreground"/> and <see cref="SharpDX.DirectInput.CooperativeLevel.Background"/> at the same time. This apply as well to <see cref="SharpDX.DirectInput.CooperativeLevel.Exclusive"/> and <see cref="SharpDX.DirectInput.CooperativeLevel.NonExclusive"/>.</para>
        ///  <para>When the mouse is acquired with exclusive access, the mouse pointer is removed from the screen until the device is unacquired.</para>	
        ///  <para>Applications that select the background exclusive mode cooperative level are not guaranteed to retain access to the device if another application requests exclusive access. When a background exclusive mode application loses access, calls to DirectInput device methods will fail and return <see cref="SharpDX.DirectInput.ResultCode.NotAcquired"/>. The application can regain access to the device by manually unacquiring the device and reaquiring it.</para>	
        ///  <para>Applications must call this method before acquiring the device by using the <see cref="SharpDX.DirectInput.Device"/> method.</para>	
        /// </remarks>	
        /// <unmanaged>HRESULT IDirectInputDevice8W::SetCooperativeLevel([In] HWND arg0,[In] DISCL arg1)</unmanaged>	
        public void SetCooperativeLevel(Control control, CooperativeLevel level)
        {
            SetCooperativeLevel(control.Handle, level);
        }
示例#13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:SharpDX.DirectSound.FullDuplex" /> class.
 /// </summary>
 /// <param name="captureDevice" />
 /// <param name="playbackDevice" />
 /// <param name="captureDescription" />
 /// <param name="bufferDescription" />
 /// <param name="windowHandle" />
 /// <param name="level" />
 /// <param name="captureBuffer" />
 /// <param name="secondaryBuffer" />
 public FullDuplex(Guid captureDevice, Guid playbackDevice, CaptureBufferDescription captureDescription, SoundBufferDescription bufferDescription, IntPtr windowHandle, CooperativeLevel level, out CaptureBuffer captureBuffer, out SecondarySoundBuffer secondaryBuffer)
 {
     DSound.FullDuplexCreate(captureDevice, playbackDevice, captureDescription, bufferDescription, windowHandle, (int) level, this,
                             out captureBuffer, out secondaryBuffer, null);
 }
示例#14
0
文件: Device.cs 项目: rbernon/monoDX
 public void SetCooperativeLevel(Control owner, CooperativeLevel level)
 {
 }
示例#15
0
文件: Device.cs 项目: rbernon/monoDX
 public void SetCooperativeLevel(IntPtr owner, CooperativeLevel level)
 {
     throw new NotImplementedException();
 }