Ejemplo n.º 1
0
 public static void Init(Form mainWindow)
 {
     var dinput = new DirectInput();
     _keyboard = new Keyboard(dinput);
     _keyboard.Acquire();
     _mouse = new Mouse(dinput);
     _mouse.Acquire();
     dinput.Dispose();
     dinput = null;
 }
Ejemplo n.º 2
0
        public Input()
        {
            _directInput = new DirectInput();

            try
            {
                Result result;

                _keyboard = new Keyboard(_directInput);

                IntPtr handle = Engine.GameEngine.Window;

                if ((result = _keyboard.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Background)) != ResultCode.Success)
                {
                    Engine.GameEngine.Exception.Exceptions.Add(new ExceptionData(result.Description,
                        result.Name, "keyboard cooperation"));
                }

                _mouse = new Mouse(_directInput);

                if ((result = _mouse.SetCooperativeLevel(handle, CooperativeLevel.Foreground | CooperativeLevel.Nonexclusive)) != ResultCode.Success)
                {
                    Engine.GameEngine.Exception.Exceptions.Add(new ExceptionData(result.Description,
                        result.Name, "mouse cooperation"));
                }

                if ((result = _keyboard.Acquire()) != ResultCode.Success)
                {
                    Engine.GameEngine.Exception.Exceptions.Add(new ExceptionData(result.Description,
                        result.Name, "keyboard acquire"));
                }

                if ((result = _mouse.Acquire()) != ResultCode.Success)
                {
                    Engine.GameEngine.Exception.Exceptions.Add(new ExceptionData(result.Description,
                        result.Name, "mouse acquire"));
                }

                Engine.GameEngine.Exception.Exceptions.Add(new ExceptionData("worked", "worked", "worked"));
            }
            catch (DirectInputException e)
            {
                Engine.GameEngine.Exception.Exceptions.Add(new ExceptionData(e.Message, e.Source, e.StackTrace));
            }
            catch (Exception e)
            {
                Engine.GameEngine.Exception.Exceptions.Add(new ExceptionData(e.Message, e.Source, e.StackTrace));
            }
            finally
            {
                Dispose();
            }
        }
Ejemplo n.º 3
0
        void CreateDevice()
        {
            // make sure that DirectInput has been initialized
            DirectInput dinput = new DirectInput();

            // build up cooperative flags
            CooperativeLevel cooperativeLevel;

            if (exclusiveRadio.Checked)
                cooperativeLevel = CooperativeLevel.Exclusive;
            else
                cooperativeLevel = CooperativeLevel.Nonexclusive;

            if (foregroundRadio.Checked)
                cooperativeLevel |= CooperativeLevel.Foreground;
            else
                cooperativeLevel |= CooperativeLevel.Background;

            // create the device
            try
            {
                mouse = new Mouse(dinput);
                mouse.SetCooperativeLevel(this, cooperativeLevel);
            }
            catch (DirectInputException e)
            {
                MessageBox.Show(e.Message);
                return;
            }

            if (!immediateRadio.Checked)
            {
                // since we want to use buffered data, we need to tell DirectInput
                // to set up a buffer for the data
                mouse.Properties.BufferSize = 8;
            }

            // acquire the device
            mouse.Acquire();

            // set the timer to go off 12 times a second to read input
            // NOTE: Normally applications would read this much faster.
            // This rate is for demonstration purposes only.
            timer.Interval = 1000 / 12;
            timer.Start();
        }
Ejemplo n.º 4
0
        public Input(Form window)
        {
            _window = window;
            _di = new DirectInput();

            _keyboard = new Keyboard(_di);
            //_keyboard.SetCooperativeLevel(_window.Handle, CooperativeLevel.Background | CooperativeLevel.Nonexclusive);
            _keyboard.Acquire();
            Log.Info("Keyboard aquired");

            _mouse = new Mouse(_di);
            //_mouse.SetCooperativeLevel(_window.Handle, CooperativeLevel.Background | CooperativeLevel.Nonexclusive);
            _mouse.Acquire();
            Log.Info("Mouse aquired");

            _pressStamp = 0;
        }
Ejemplo n.º 5
0
        public override Action Start()
        {
            IntPtr handle = Process.GetCurrentProcess().MainWindowHandle;

            mouseDevice = new Mouse(directInputInstance);
            if (mouseDevice == null)
                throw new Exception("Failed to create mouse device");

            mouseDevice.SetCooperativeLevel(handle, CooperativeLevel.Background | CooperativeLevel.Nonexclusive);
            mouseDevice.Properties.AxisMode = DeviceAxisMode.Relative;   // Get delta values
            mouseDevice.Acquire();

            getButtonPressedStrategy = new GetPressedStrategy<int>(IsButtonDown);
            setButtonPressedStrategy = new SetPressedStrategy(SetButtonDown, SetButtonUp);
          
            OnStarted(this, new EventArgs());
            return null;
        }
Ejemplo n.º 6
0
        //-----------------------------------------------------------------------
        public override System.Action Start()
        {
            IntPtr handle = Process.GetCurrentProcess().MainWindowHandle;

            mouseDevice = new Mouse(directInputInstance);
            if (mouseDevice == null)
            {
                throw new Exception("Failed to create mouse device");
            }

            mouseDevice.SetCooperativeLevel(handle, CooperativeLevel.Background | CooperativeLevel.Nonexclusive);
            mouseDevice.Properties.AxisMode = DeviceAxisMode.Relative;   // Get delta values
            mouseDevice.Acquire();

            getButtonPressedStrategy = new GetPressedStrategy(IsButtonDown);
            setButtonPressedStrategy = new SetPressedStrategy(SetButtonDown, SetButtonUp);

            OnStarted(this, new EventArgs());
            return(null);
        }
Ejemplo n.º 7
0
        internal bool Initialize(SystemConfiguration configuration, IntPtr windowsHandle)
        {
            // Screen the screen size which will be used for positioning the mouse cursor.
            _ScreenWidth  = configuration.Width;
            _ScreenHeight = configuration.Height;

            // Initialize the location of the mouse on the screen.
            _MouseX = 0;
            _MouseY = 0;

            // Initialize the main direct input interface.
            _DirectInput = new DirectInput();

            // Initialize the direct interface for the keyboard.
            _Keyboard = new Keyboard(_DirectInput);
            _Keyboard.Properties.BufferSize = 256;

            // Set the cooperative level of the keyboard to not share with other programs.
            _Keyboard.SetCooperativeLevel(windowsHandle, CooperativeLevel.Foreground | CooperativeLevel.Exclusive);

            // Now acquire the keyboard.
            if (_Keyboard.Acquire().Failure)
            {
                return(false);
            }

            // Initialize the direct interface for the mouse.
            _Mouse = new Mouse(_DirectInput);
            _Mouse.Properties.AxisMode = DeviceAxisMode.Relative;

            // Set the cooperative level of the mouse to share with other programs.
            _Mouse.SetCooperativeLevel(windowsHandle, CooperativeLevel.Foreground | CooperativeLevel.NonExclusive);

            // Now acquire the mouse.
            if (_Mouse.Acquire().Failure)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 8
0
        public Camera(Device device, float aspectRatio)
        {
            _globals = new Constants();
            _aspect  = aspectRatio;
            _fov     = 1.3f;
            View     = Matrix.LookAtLH(new Vector3(0, 0, -20f), Vector3.Zero, Vector3.UnitY);
            SetPerspective();


            _device = device;
            //Projection = Matrix.PerspectiveFovLH(_fov, aspectRatio, 0.0001f, 100000);
            //Projection = Matrix.OrthoLH(10 * _aspect, 10, 0.0001f, 100000);

            var data = new DataStream(Marshal.SizeOf(typeof(Constants)), true, true);

            data.Write(_globals);
            data.Position = 0;

            _globalConstants = new Buffer(device,                            //Device
                                          data,                              //Stream
                                          Marshal.SizeOf(typeof(Constants)), // Size
                                          ResourceUsage.Default,
                                          BindFlags.ConstantBuffer,
                                          CpuAccessFlags.None,
                                          ResourceOptionFlags.None,
                                          64);

            device.ImmediateContext.PixelShader.SetConstantBuffer(_globalConstants, 0);


            Input    = new DirectInput();
            Keyboard = new Keyboard(Input);
            Mouse    = new Mouse(Input);
            Keyboard.Acquire();
            Mouse.Acquire();
            lastMouseX = Cursor.Position.X;
            lastMouseY = Cursor.Position.Y;

            ResetCamera();
        }
Ejemplo n.º 9
0
        private bool ReadMouse()
        {
            var resultCode = ResultCode.Ok;

            _MouseState = new MouseState();
            try
            {
                // Read the mouse device.
                _Mouse.GetCurrentState(ref _MouseState);
            }
            catch (SharpDX.SharpDXException ex)
            {
                resultCode = ex.Descriptor;
            }
            catch (Exception)
            {
                return(false);
            }

            // If the mouse lost focus or was not acquired then try to get control back.
            if (resultCode == ResultCode.InputLost || resultCode == ResultCode.NotAcquired)
            {
                try
                {
                    _Mouse.Acquire();
                }
                catch
                {
                }

                return(true);
            }

            if (resultCode == ResultCode.Ok)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 10
0
        public bool Initialise(Dimension screenSize, IntPtr windowHandle)
        {
            ScreenSize    = new Dimension(screenSize.Width, screenSize.Height);
            MousePosition = new Coordinate2D <int>(0, 0);
            DirectInput   = new DirectInput();

            Keyboard = new Keyboard(DirectInput);
            Keyboard.Properties.BufferSize = 256;
            Keyboard.SetCooperativeLevel(windowHandle, CooperativeLevel.Foreground | CooperativeLevel.NonExclusive);

            var result = true;

            try
            {
                Keyboard.Acquire();
            }
            catch (SharpDXException ex)
            {
                Log.WriteToFile(ErrorLevel.Error, "Input.Initialise (Keyboard)", ex, true);

                result = false;
            }

            Mouse = new Mouse(DirectInput);
            Mouse.Properties.AxisMode = DeviceAxisMode.Relative;
            Mouse.SetCooperativeLevel(windowHandle, CooperativeLevel.Foreground | CooperativeLevel.NonExclusive);

            try
            {
                Mouse.Acquire();
            }
            catch (SharpDXException ex)
            {
                Log.WriteToFile(ErrorLevel.Error, "Input.Initialise (Mouse)", ex, true);

                result = false;
            }

            return(result);
        }
Ejemplo n.º 11
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();
        }
Ejemplo n.º 12
0
        public void Update()
        {
            if (_keyboard.Acquire().IsFailure || _mouse.Acquire().IsFailure || (_joystick1?.Acquire().IsFailure ?? false))
            {
                return;
            }

            _keyboardStateLast    = _keyboardStateCurrent;
            _keyboardStateCurrent = _keyboard.GetCurrentState();

            _mouseStateLast    = _mouseStateCurrent;
            _mouseStateCurrent = _mouse.GetCurrentState();

            _joy1StateLast    = _joy1StateCurrent;
            _joy1StateCurrent = _joystick1?.GetCurrentState();

            if (_controller1.IsConnected)
            {
                _controller1StateLast    = _controller1StateCurrent;
                _controller1StateCurrent = _controller1.GetState().Gamepad;
            }
        }
Ejemplo n.º 13
0
        // Methods.
        internal bool Initialize(DSystemConfiguration configuration, IntPtr windowsHandle)
        {
            // Screen the screen size which will be used for positioning the mouse cursor.
            _ScreenWidth  = configuration.Width;
            _ScreenHeight = configuration.Height;

            // Initialize the location of the mouse on the screen.
            _MouseX = 0;
            _MouseY = 0;

            // Initialize the main direct input interface.
            _DirectInput = new DirectInput();

            #region Keyboard related Initiailization
            // Initialize the direct interface for the keyboard.
            _Keyboard = new Keyboard(_DirectInput);
            _Keyboard.Properties.BufferSize = 256;

            // Set the cooperative level of the keyboard to not share with other programs.
            // use 'CooperativeLevel.Background' for debugging purpose on Both the Mouse and Keyboard as well as NonExclusive on the keybaord.
            _Keyboard.SetCooperativeLevel(windowsHandle, CooperativeLevel.Foreground | CooperativeLevel.NonExclusive);

            _Keyboard.Acquire();
            #endregion

            #region Mouse related Initiailization
            // Initialize the direct interface for the mouse.
            _Mouse = new Mouse(_DirectInput);
            _Mouse.Properties.AxisMode = DeviceAxisMode.Relative;

            // Set the cooperative level of the mouse to share with other programs.
            _Mouse.SetCooperativeLevel(windowsHandle, CooperativeLevel.Foreground | CooperativeLevel.NonExclusive);

            _Mouse.Acquire();
            #endregion

            return(true);
        }
Ejemplo n.º 14
0
        public Camera(Graphics graphics)
        {
            _graphics     = graphics;
            Position      = new Vector3(Game.StartPosition.X, Game.StartPosition.Y, Game.StartPosition.Z);
            LookAt        = Vector3.Normalize(new Vector3(1, 0, 0));
            InitialLookAt = LookAt;

            var directInput = new DirectInput();

            Keyboard = new Keyboard(directInput);
            Keyboard.Properties.BufferSize = 128;
            Keyboard.Acquire();

            Mouse = new Mouse(directInput);
            Mouse.Properties.AxisMode   = DeviceAxisMode.Relative;
            Mouse.Properties.BufferSize = 128;
            Mouse.Acquire();

            VoxelInHand = VoxelDefinition.Sand;
            _voxelDefinitionIndexInHand = VoxelDefinition.RegisteredDefinitions.IndexOf(VoxelInHand.Type);

            IsInAir = true;
        }
Ejemplo n.º 15
0
        public AppWindow(string title)
        {
            Trace.TraceInformation("Initializing Graphics");
            window            = new RenderForm(title);
            window.Icon       = Properties.Resources.Iconshow_General_Performance;
            window.ClientSize = new Size((int)ScreenSize.X, (int)ScreenSize.Y);

            bool isWindowed = true;

            swapChainDescription = new SwapChainDescription()
            {
                BufferCount       = 1,
                Flags             = SwapChainFlags.None,
                IsWindowed        = isWindowed,
                ModeDescription   = new ModeDescription((int)ScreenSize.X, (int)ScreenSize.Y, new Rational(1, 60), Format.R8G8B8A8_UNorm),
                OutputHandle      = window.Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput
            };

            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, swapChainDescription, out graphicsDevice, out swapChain);
            graphicsContext = graphicsDevice.ImmediateContext;

            factory = swapChain.GetParent <Factory>();
            factory.MakeWindowAssociation(window.Handle, WindowAssociationFlags.IgnoreAll);

            BuildBuffer();

            input    = new DirectInput();
            Keyboard = new Keyboard(input);
            Keyboard.Acquire();
            Mouse = new Mouse(input);
            Mouse.Acquire();
            KeyState   = new KeyboardState();
            MouseState = new MouseState();
        }
Ejemplo n.º 16
0
 private void ReadMouse()
 {
     try
     {
         _mouseState = _mouse.GetCurrentState();
     }
     catch (SharpDXException e)
     {
         if (e.Descriptor == ResultCode.InputLost || e.Descriptor == ResultCode.NotAcquired)
         {
             try
             {
                 _mouse.Acquire();
                 _mouseState = _mouse.GetCurrentState();
             }
             catch (SharpDXException)
             { }
         }
         else
         {
             throw;
         }
     }
 }
Ejemplo n.º 17
0
        public Camera(Device device, float aspectRatio)
        {
            _globals = new Constants();
            _aspect = aspectRatio;
            _fov = 1.3f;
            View = Matrix.LookAtLH(new Vector3(0, 0, -20f), Vector3.Zero, Vector3.UnitY);
            SetPerspective();

            _device = device;
            //Projection = Matrix.PerspectiveFovLH(_fov, aspectRatio, 0.0001f, 100000);
            //Projection = Matrix.OrthoLH(10 * _aspect, 10, 0.0001f, 100000);

            var data = new DataStream(Marshal.SizeOf(typeof(Constants)), true, true);
            data.Write(_globals);
            data.Position = 0;

            _globalConstants = new Buffer(device, //Device
                data, //Stream
                Marshal.SizeOf(typeof(Constants)), // Size
                ResourceUsage.Default,
                BindFlags.ConstantBuffer,
                CpuAccessFlags.None,
                ResourceOptionFlags.None,
                64);

            device.ImmediateContext.PixelShader.SetConstantBuffer(_globalConstants, 0);

            DirectInput input = new DirectInput();
            keyboard = new Keyboard(input);
            mouse = new Mouse(input);
            keyboard.Acquire();
            mouse.Acquire();
            lastMouseX = Cursor.Position.X;
            lastMouseY = Cursor.Position.Y;

            ResetCamera();
        }
        public InputDeviceManager(Window window, MainWindow.ToggleOverlayCallback _toggleOverlayCallback)
        {
            _directInput = new DirectInput();
            var deviceInstances = _directInput.GetDevices();

            WindowHelper =
                new WindowInteropHelper(window);

            this._toggleOverlayCallback = _toggleOverlayCallback;

            LoadWhiteList();

            LoadBlackList();

            Logger.Info("Starting Device Search. Expand Search: " +
                        (_settings.GetClientSetting(SettingsKeys.ExpandControls).BoolValue));

            foreach (var deviceInstance in deviceInstances)
            {
                //Workaround for Bad Devices that pretend to be joysticks
                if (!IsBlackListed(deviceInstance.ProductGuid))
                {
                    Logger.Info("Found Device ID:" + deviceInstance.ProductGuid +
                                " " +
                                deviceInstance.ProductName.Trim().Replace("\0", "") + " Usage: " +
                                deviceInstance.UsagePage + " Type: " +
                                deviceInstance.Type);


                    if (deviceInstance.Type == DeviceType.Keyboard)
                    {
                        Logger.Info("Adding Device ID:" + deviceInstance.ProductGuid +
                                    " " +
                                    deviceInstance.ProductName.Trim().Replace("\0", ""));
                        var device = new Keyboard(_directInput);

                        device.SetCooperativeLevel(WindowHelper.Handle,
                                                   CooperativeLevel.Background | CooperativeLevel.NonExclusive);
                        device.Acquire();

                        _inputDevices.Add(device);
                    }
                    else if (deviceInstance.Type == DeviceType.Mouse)
                    {
                        Logger.Info("Adding Device ID:" + deviceInstance.ProductGuid + " " +
                                    deviceInstance.ProductName.Trim().Replace("\0", ""));
                        var device = new Mouse(_directInput);

                        device.SetCooperativeLevel(WindowHelper.Handle,
                                                   CooperativeLevel.Background | CooperativeLevel.NonExclusive);
                        device.Acquire();

                        _inputDevices.Add(device);
                    }
                    else if (((deviceInstance.Type >= DeviceType.Joystick) &&
                              (deviceInstance.Type <= DeviceType.FirstPerson)) ||
                             IsWhiteListed(deviceInstance.ProductGuid))
                    {
                        var device = new Joystick(_directInput, deviceInstance.InstanceGuid);

                        Logger.Info("Adding ID:" + deviceInstance.ProductGuid + " " +
                                    deviceInstance.ProductName.Trim().Replace("\0", ""));

                        device.SetCooperativeLevel(WindowHelper.Handle,
                                                   CooperativeLevel.Background | CooperativeLevel.NonExclusive);
                        device.Acquire();

                        _inputDevices.Add(device);
                    }
                    else if (SettingsStore.Instance.GetClientSetting(SettingsKeys.ExpandControls).BoolValue)
                    {
                        Logger.Info("Adding (Expanded Devices) ID:" + deviceInstance.ProductGuid + " " +
                                    deviceInstance.ProductName.Trim().Replace("\0", ""));

                        var device = new Joystick(_directInput, deviceInstance.InstanceGuid);

                        device.SetCooperativeLevel(WindowHelper.Handle,
                                                   CooperativeLevel.Background | CooperativeLevel.NonExclusive);
                        device.Acquire();

                        _inputDevices.Add(device);

                        Logger.Info("Added (Expanded Device) ID:" + deviceInstance.ProductGuid + " " +
                                    deviceInstance.ProductName.Trim().Replace("\0", ""));
                    }
                }
                else
                {
                    Logger.Info("Found but ignoring blacklist device  " + deviceInstance.ProductGuid + " Instance: " +
                                deviceInstance.InstanceGuid + " " +
                                deviceInstance.ProductName.Trim().Replace("\0", "") + " Type: " + deviceInstance.Type);
                }
            }
        }
Ejemplo n.º 19
0
        //-----------------------------------------------------------------------
        public override System.Action Start()
        {
            IntPtr handle = Process.GetCurrentProcess().MainWindowHandle;

            MouseDevice = new Mouse(DirectInputInstance);
            if (MouseDevice == null)
                throw new Exception("Failed to create mouse device");

            MouseDevice.SetCooperativeLevel(handle, CooperativeLevel.Background | CooperativeLevel.Nonexclusive);
            MouseDevice.Properties.AxisMode = DeviceAxisMode.Relative;   // Get delta values
            MouseDevice.Acquire();

            OnStarted(this, new EventArgs());
            return null;
        }
        public void InitDevices()
        {
            Logger.Info("Starting Device Search. Expand Search: " +
                        (_globalSettings.GetClientSettingBool(GlobalSettingsKeys.ExpandControls)));

            var deviceInstances = _directInput.GetDevices();

            foreach (var deviceInstance in deviceInstances)
            {
                //Workaround for Bad Devices that pretend to be joysticks
                if (IsBlackListed(deviceInstance.ProductGuid))
                {
                    Logger.Info("Found but ignoring blacklist device  " + deviceInstance.ProductGuid + " Instance: " +
                                deviceInstance.InstanceGuid + " " +
                                deviceInstance.ProductName.Trim().Replace("\0", "") + " Type: " + deviceInstance.Type);
                    continue;
                }

                Logger.Info("Found Device ID:" + deviceInstance.ProductGuid +
                            " " +
                            deviceInstance.ProductName.Trim().Replace("\0", "") + " Usage: " +
                            deviceInstance.UsagePage + " Type: " +
                            deviceInstance.Type);
                if (_inputDevices.ContainsKey(deviceInstance.InstanceGuid))
                {
                    Logger.Info("Already have device:" + deviceInstance.ProductGuid +
                                " " +
                                deviceInstance.ProductName.Trim().Replace("\0", ""));
                    continue;
                }


                if (deviceInstance.Type == DeviceType.Keyboard)
                {
                    Logger.Info("Adding Device ID:" + deviceInstance.ProductGuid +
                                " " +
                                deviceInstance.ProductName.Trim().Replace("\0", ""));
                    var device = new Keyboard(_directInput);

                    device.SetCooperativeLevel(WindowHelper.Handle,
                                               CooperativeLevel.Background | CooperativeLevel.NonExclusive);
                    device.Acquire();

                    _inputDevices.Add(deviceInstance.InstanceGuid, device);
                }
                else if (deviceInstance.Type == DeviceType.Mouse)
                {
                    Logger.Info("Adding Device ID:" + deviceInstance.ProductGuid + " " +
                                deviceInstance.ProductName.Trim().Replace("\0", ""));
                    var device = new Mouse(_directInput);

                    device.SetCooperativeLevel(WindowHelper.Handle,
                                               CooperativeLevel.Background | CooperativeLevel.NonExclusive);
                    device.Acquire();

                    _inputDevices.Add(deviceInstance.InstanceGuid, device);
                }
                else if (((deviceInstance.Type >= DeviceType.Joystick) &&
                          (deviceInstance.Type <= DeviceType.FirstPerson)) ||
                         IsWhiteListed(deviceInstance.ProductGuid))
                {
                    var device = new Joystick(_directInput, deviceInstance.InstanceGuid);

                    Logger.Info("Adding ID:" + deviceInstance.ProductGuid + " " +
                                deviceInstance.ProductName.Trim().Replace("\0", ""));

                    device.SetCooperativeLevel(WindowHelper.Handle,
                                               CooperativeLevel.Background | CooperativeLevel.NonExclusive);
                    device.Acquire();

                    _inputDevices.Add(deviceInstance.InstanceGuid, device);
                }
                else if (GlobalSettingsStore.Instance.GetClientSettingBool(GlobalSettingsKeys.ExpandControls))
                {
                    Logger.Info("Adding (Expanded Devices) ID:" + deviceInstance.ProductGuid + " " +
                                deviceInstance.ProductName.Trim().Replace("\0", ""));

                    var device = new Joystick(_directInput, deviceInstance.InstanceGuid);

                    device.SetCooperativeLevel(WindowHelper.Handle,
                                               CooperativeLevel.Background | CooperativeLevel.NonExclusive);
                    device.Acquire();

                    _inputDevices.Add(deviceInstance.InstanceGuid, device);

                    Logger.Info("Added (Expanded Device) ID:" + deviceInstance.ProductGuid + " " +
                                deviceInstance.ProductName.Trim().Replace("\0", ""));
                }
            }
        }
Ejemplo n.º 21
0
 public DirectInputMouse(SharpDX.DirectInput.DirectInput nativeDirectInput)
 {
     _nativeMouse = new Mouse(nativeDirectInput);
     _nativeMouse.Acquire();
     _previousMouseState = _nativeMouse.GetCurrentState();
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Initialize the input.
        /// </summary>
        public static void ModuleInit()
        {
            directInput = new DirectInput();
            keyboard = new Keyboard(directInput);
            keyboard.SetCooperativeLevel(Scene.Instance.GraphicsEngine.Form, CooperativeLevel.Nonexclusive | CooperativeLevel.Background);
            keyboard.Acquire();
            mouse = new Mouse(directInput);
            mouse.SetCooperativeLevel(Scene.Instance.GraphicsEngine.Form, CooperativeLevel.Nonexclusive | CooperativeLevel.Background);
            mouse.Acquire();

            s_lastFrameState = keyboard.GetCurrentState();
            s_thisState = s_lastFrameState;
            s_lastFrameMouseState = mouse.GetCurrentState();
            s_thisMouseState = s_lastFrameMouseState;
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Initializes SlimDX and input devices.
        /// </summary>
        /// <param name="caption">Window caption string.</param>
        public FrameworkForm(string caption)
            : base(caption)
        {
            SwapChainDescription description = new SwapChainDescription()
            {
                BufferCount       = 1,
                Flags             = SwapChainFlags.None,
                IsWindowed        = true,
                ModeDescription   = new ModeDescription(ClientSize.Width, ClientSize.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                OutputHandle      = Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput
            };

            try
            {
#if DEBUG
                Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.Debug, description, out graphicsDevice, out swapChain);
#else
                Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, description, out graphicsDevice, out swapChain);
#endif
            }
            catch
            {
                MessageBox.Show("An error has occurred during initialization process.");
                Environment.Exit(0);
            }
            finally
            {
                if (graphicsDevice.FeatureLevel != FeatureLevel.Level_11_0)
                {
                    MessageBox.Show("This program requires DirectX 11. Your version is " + graphicsDevice.FeatureLevel.ToString() + ".");
                    Environment.Exit(0);
                }
            }

            Factory factory = swapChain.GetParent <Factory>();
            factory.SetWindowAssociation(Handle, WindowAssociationFlags.IgnoreAltEnter);
            KeyDown += (o, e) =>
            {
                // Fixes Alt-Enter keyboard input bug in SlimDX.
                if (e.Alt && e.KeyCode == Keys.Enter)
                {
                    swapChain.IsFullScreen = !swapChain.IsFullScreen;
                }

                // Makes screenshot.
                if (e.KeyCode == Keys.F12)
                {
                    MakeScreenshot(Application.StartupPath);
                }
            };

            SizeChanged += (o, e) =>
            {
                // Dispose old resources.
                if (renderTargetView != null)
                {
                    renderTargetView.Dispose();
                }
                if (backBufferTexture != null)
                {
                    backBufferTexture.Dispose();
                }

                // Resize buffers.
                swapChain.ResizeBuffers(1, ClientSize.Width, ClientSize.Height, Format.R8G8B8A8_UNorm, SwapChainFlags.None);

                InitializeOutputMerger();

                camera.UpdateProjection();

                postProcess.Initialize(ClientSize.Width, ClientSize.Height);
            };

            fillMode = FillMode.Solid;
            InitializeOutputMerger();

            // Initializes input devices.
            DirectInput directInput = new DirectInput();
            keyboard = new Keyboard(directInput);
            keyboard.Acquire();
            mouse = new Mouse(directInput);
            mouse.Acquire();

            camera       = new Camera(graphicsDevice, new Vector3(50, 50, 50), new Vector3(0, 0, 0), 0.1f, 1000.0f);
            textures     = new List <TexturePack>();
            postProcess  = new PostProcess(graphicsDevice, ClientSize.Width, ClientSize.Height);
            quadRenderer = new QuadRenderer(graphicsDevice);
        }
Ejemplo n.º 24
0
 public static void InitMouse()
 {
     device = new DirectInput();
     mouse  = new Mouse(device);
     mouse.Acquire();
 }
Ejemplo n.º 25
0
        private void HandleMouse()
        {
            if (mouse.Acquire().IsFailure)
            {
                return;
            }
            if (mouse.Poll().IsFailure)
            {
                return;
            }
            try
            {
                mouse.GetCurrentState(ref mouseState);

                bool[] buttons = mouseState.GetButtons();

                for (int i = 0; i < buttons.Length && i < 5; i++)
                {
                    if (buttons[i] != currentMouseButtons[i])
                    {
                        switch (i)
                        {
                        case 0:
                            InputEvent(EmuKeys.Mouse1, buttons[i]);
                            break;

                        case 1:
                            InputEvent(EmuKeys.Mouse2, buttons[i]);
                            break;

                        case 2:
                            InputEvent(EmuKeys.Mouse3, buttons[i]);
                            break;

                        case 3:
                            InputEvent(EmuKeys.Mouse4, buttons[i]);
                            break;

                        case 4:
                            InputEvent(EmuKeys.Mouse5, buttons[i]);
                            break;
                        }
                        currentMouseButtons[i] = buttons[i];
                    }
                }
                int newMouseX = Cursor.Position.X; //Not even going to bother with attempting to use crazy relative Direct Input mouse data
                int newMouseY = Cursor.Position.Y;
                if (newMouseX != mouseX)
                {
                    InputScalerEvent(EmuKeys.MouseX, newMouseX);
                }
                if (newMouseY != mouseY)
                {
                    InputScalerEvent(EmuKeys.MouseY, newMouseY);
                }
                mouseX = newMouseX;
                mouseY = newMouseY;
            }
            catch
            {
                mouse.Acquire();
            }
        }