Exemple #1
0
        /// <summary>
        /// 指定されたジョイパッドを接続
        /// </summary>
        /// <param name="name"></param>
        internal static bool DI_Connect(System.Windows.Forms.Form self, string name)
        {
            // ジョイパッド一覧を取得
            Device     d       = null;
            DeviceList devList = Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly);

            foreach (DeviceInstance dev in devList)
            {
                d = new Microsoft.DirectX.DirectInput.Device(dev.InstanceGuid);
                if (d.DeviceInformation.ProductName == name)
                {
                    d.SetCooperativeLevel(self, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
                    break;
                }
            }

            if (d == null)
            {
                return(false);
            }

            // 占有権を取る
            d.SetDataFormat(DeviceDataFormat.Joystick);
            d.Acquire();
            DI_joypad = d;

            // デバイス情報を取得する
            DeviceName = d.DeviceInformation.ProductName;
            NumAxis    = d.Caps.NumberAxes;
            NumPovs    = d.Caps.NumberPointOfViews;
            NumBtns    = d.Caps.NumberButtons;

            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Plugin entry point
        /// </summary>
        public override void Load()
        {
            drawArgs = ParentApplication.WorldWindow.DrawArgs;

            // Find the first space pilot or traveler device
            DeviceList dl = Microsoft.DirectX.DirectInput.Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly);

            dl.MoveNext();
            while (dl.Current != null)
            {
                if ((((DeviceInstance)dl.Current).ProductName != "SpacePilot") &&
                    (((DeviceInstance)dl.Current).ProductName != "SpaceTraveler USB"))
                {
                    dl.MoveNext();
                }
                else
                {
                    break;
                }
            }
            if (dl.Current == null)
            {
                throw new ApplicationException("No SpacePilot detected.  Please check your connections and verify your device appears in Control panel -> Game Controllers.");
            }
            DeviceInstance di = (DeviceInstance)dl.Current;

            spacePilot = new Microsoft.DirectX.DirectInput.Device(di.InstanceGuid);
            spacePilot.SetDataFormat(DeviceDataFormat.Joystick);
            spacePilot.SetCooperativeLevel(ParentApplication,
                                           CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background);


            if (di.ProductName == "SpacePilot")
            {
                m_spacePilot = true;
            }

            foreach (DeviceObjectInstance d in spacePilot.Objects)
            {
                // For axes that are returned, set the DIPROP_RANGE property for the
                // enumerated axis in order to scale min/max values.
                if ((d.ObjectId & (int)DeviceObjectTypeFlags.Axis) != 0)
                {
                    // Try to set the AXISRANGE for the axis but this seems ignored by space pilot
                    spacePilot.Properties.SetRange(ParameterHow.ById, d.ObjectId, new InputRange(-AXISRANGE, AXISRANGE));
                    spacePilot.Properties.SetDeadZone(ParameterHow.ById, d.ObjectId, 1000);                     // 10%

                    // change the axis mode to absolute to work more like how its expected
                    spacePilot.Properties.AxisModeAbsolute = false;
                }
            }

            spacePilot.Acquire();

            // Start a new thread to poll the SpacePilot
            // TODO: The Device supports events, use them
            joyThread = new Thread(new ThreadStart(SpacePilotLoop));
            joyThread.IsBackground = true;
            joyThread.Start();
        }
Exemple #3
0
        //privateなメソッド=====================
        /// <summary>
        /// デバイスの初期化
        /// </summary>
        static void Initialize()
        {
            //keyMap = PS2KeyMap;

            // DirectInputデバイスのリストを取得
            DInput.DeviceList controllers =
                DInput.Manager.GetDevices(
                    DInput.DeviceClass.GameControl,
                    DInput.EnumDevicesFlags.AllDevices);

            //Joystickのデバイスを作る器
            DInput.Device d;

            //取得したデバイスのリストをforeachして1つづつjoysticksに登録
            foreach (DInput.DeviceInstance i in controllers)
            {
                //デバイスの生成
                d = new DInput.Device(i.InstanceGuid);

                //各種フラグの設定。Backgroundだと第一引数のFormはnullでいい
                d.SetCooperativeLevel(null,
                                      DInput.CooperativeLevelFlags.NonExclusive
                                      | DInput.CooperativeLevelFlags.NoWindowsKey
                                      | DInput.CooperativeLevelFlags.Background
                                      );

                //Joystickタイプのデータフォーマットを設定
                d.SetDataFormat(DInput.DeviceDataFormat.Joystick);

                //アナログスティックなどのAxis要素を持つDeviceObjectInstanceの出力レンジを設定
                foreach (DInput.DeviceObjectInstance oi in d.Objects)
                {
                    if ((oi.ObjectId & (int)DInput.DeviceObjectTypeFlags.Axis) != 0)
                    {
                        d.Properties.SetRange(
                            DInput.ParameterHow.ById,
                            oi.ObjectId,
                            new DInput.InputRange(-1000, 1000));
                    }
                }

                //Axisの絶対位置モードを設定
                d.Properties.AxisModeAbsolute = true;

                //とりあえずデバイスを動かす
                try { d.Acquire(); }
                catch (Microsoft.DirectX.DirectXException) { }

                //作ったJoystickのDeviceをJoystickリストに追加
                joysticks.Add(d);

                //Joystickの状態を保持させる為のjsstatesを用意、とりあえず現在と以前の状態で2つ用意してみる
                //Geek:一個でよくね……?
                jsStates.Add(new DInput.JoystickState());
            }
        }
Exemple #4
0
        public bool InitJoystick(Form1 zw, int deviceNum)
        {
            //DirectInput dinput = new DirectInput();
            //System.Collections.Generic.IList<DeviceInstance> deviceList = dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly);
            //DirectInput.DeviceList deviceList = DirectInput.Manager.GetDevices(DirectInput.DeviceClass.GameControl, DirectInput.EnumDevicesFlags.AttachedOnly);
            try {
                joystick = new DirectInput.Device(joystickList[deviceNum].InstanceGuid);
                joystick.SetCooperativeLevel(zw, DirectInput.CooperativeLevelFlags.NonExclusive | DirectInput.CooperativeLevelFlags.Background);
                joystick.SetDataFormat(DirectInput.DeviceDataFormat.Joystick);
                name = joystickList[deviceNum].ProductName;
            } catch (Microsoft.DirectX.DirectInput.InputException de) {
                System.Windows.Forms.MessageBox.Show("Couldn't connect to joystick!", "Joystick Problem", System.Windows.Forms.MessageBoxButtons.OK);
                return(false);
            }
            foreach (DirectInput.DeviceObjectInstance deviceObject in joystick.Objects)
            {
                if ((deviceObject.ObjectId & (int)DirectInput.DeviceObjectTypeFlags.Axis) != 0)
                {
                    joystick.Properties.SetRange(DirectInput.ParameterHow.ById,
                                                 deviceObject.ObjectId,
                                                 new DirectInput.InputRange(-1000, 1000));
                }

                //joystick.Properties.SetDeadZone(
                //                       DirectInput.ParameterHow.ById,
                //                       deviceObject.ObjectId,
                //                       2000);
            }
            // acquire the device
            try {
                joystick.Acquire();
            }
            catch (Microsoft.DirectX.DirectInput.InputException de) {
                System.Windows.Forms.MessageBox.Show(de.Message, "Joystick Error", System.Windows.Forms.MessageBoxButtons.OK);
                return(false);
            }

            //Initially no keys are mapped to buttons on the controller.

            /*for (int f = 0; f < joystick.Caps.NumberButtons; f++) {
             *  if (!buttonMap.ContainsKey(f))
             *      buttonMap.Add(f, -1);
             * }*/
            buttonMap = new int[joystick.Caps.NumberButtons];
            for (int f = 0; f < buttonMap.Length; f++)
            {
                buttonMap[f] = -1;
            }
            fireButtonIndex = 0; //Button 0 on the controller is 'fire' by default
            isInitialized   = true;
            return(true);
        }
        /// <summary>
        /// Initializes the mouse device.
        /// </summary>
        public MouseDevice(Form form)
        {
            mouseDevice = new DirectInput.Device(SystemGuid.Mouse);
            mouseDevice.SetCooperativeLevel(form, CooperativeLevelFlags.Background |
                CooperativeLevelFlags.NonExclusive);
            mouseDevice.SetDataFormat(DeviceDataFormat.Mouse);

            mouseDevice.Properties.AxisModeAbsolute = false;

            mouseDevice.Acquire();

            Update();
        }
Exemple #6
0
        } // MostrarTitulo().fim

        private void inicializarJoystick()
        {
            // Verifica os controles de videogames conectados
            DirectInput.DeviceList Dispositivos =
                DirectInput.Manager.GetDevices(DirectInput.DeviceClass.GameControl,
                                               DirectInput.EnumDevicesFlags.AttachedOnly);

            // Repassa a lista de controles e pega o primeiro item
            foreach (DirectInput.DeviceInstance dispositivo in Dispositivos)
            {
                joystick = new DirectInput.Device(dispositivo.InstanceGuid);

                // Quebre o foreach depois de pegar o primeiro item conectado
                break;
            }

            // Se não tiver Joystick vá embora da função...
            if (joystick == null)
            {
                return;
            }

            // Os dados do dispositivo serão tratados como dados de Joystick
            joystick.SetDataFormat(DirectInput.DeviceDataFormat.Joystick);

            // Configura nível de cooperação
            joystick.SetCooperativeLevel(this,
                                         DirectInput.CooperativeLevelFlags.Background |
                                         DirectInput.CooperativeLevelFlags.NonExclusive);

            // Configura eixo
            joystick.Properties.AxisModeAbsolute = true;

            // Configura faixa de valor retornado pelos eixos
            DirectInput.InputRange eixo_faixaValor;
            eixo_faixaValor = new DirectInput.InputRange(-5000, 5000);
            foreach (DirectInput.DeviceObjectInstance item in joystick.Objects)
            {
                int eixo_ok = item.ObjectId & (int)DirectInput.DeviceObjectTypeFlags.Axis;
                if (eixo_ok != 0)
                {
                    // Configura a faixa de valores do eixo encontrado
                    joystick.Properties.SetRange(DirectInput.ParameterHow.ById,
                                                 item.ObjectId, eixo_faixaValor);
                } // endif
            }     // endfor each

            joystick.Acquire();
        } // inicializarJoystick().fim
Exemple #7
0
        public xMouse(Control Owner, 
			Microsoft.DirectX.Direct3D.Device device, bool bWindowed)
        {
            m_Owner = Owner;
            d3ddevice = device;
            mouse = new Device(SystemGuid.Mouse);
            mouse.SetDataFormat(DeviceDataFormat.Mouse);
            mouse.SetCooperativeLevel(m_Owner,
                CooperativeLevelFlags.Background |
                CooperativeLevelFlags.NonExclusive);
            mouse.Properties.AxisModeAbsolute = false;
            buttons = new bool[256];
            m_bWindowed = bWindowed;
            m_XPos = 0f;
            m_YPos = 0f;
            m_ObjectSpace = new Vector3(0f, 0f, 0f);
            m_ObjectSpace2 = new Vector3(0f, 0f, 0f);
            m_Clicked = false;
        }
        public SplashButton(System.Windows.Forms.Form frm, 
                            D3D.Device device3D, Point location, Size dimension,
                            string normalFileName, string mouseOverFileName,
                            string mouseDownFileName, string disableFileName)
        {
            device3d = device3D;
            Location = location;
            size = dimension;

            int h = Location.Y + size.Height;
            int w = Location.X + size.Width;
            vertices = new D3D.CustomVertex.TransformedTextured[6];
            vertices[0] = new D3D.CustomVertex.TransformedTextured(new Vector4(location.X, location.Y, 0f, 1f), 0, 0);
            vertices[1] = new D3D.CustomVertex.TransformedTextured(new Vector4(w, location.Y, 0f, 1f), 1, 0);
            vertices[2] = new D3D.CustomVertex.TransformedTextured(new Vector4(location.X, h, 0f, 1f), 0, 1);
            vertices[3] = new D3D.CustomVertex.TransformedTextured(new Vector4(location.X, h, 0f, 1f), 0, 1);
            vertices[4] = new D3D.CustomVertex.TransformedTextured(new Vector4(w, location.Y, 0f, 1f), 1, 0);
            vertices[5] = new D3D.CustomVertex.TransformedTextured(new Vector4(w, h, 0f, 1f), 1, 1);
            normalTexture = D3D.TextureLoader.FromFile(device3d, normalFileName);
            mouseOverTexture = D3D.TextureLoader.FromFile(device3d, mouseOverFileName);
            mouseDownTexture = D3D.TextureLoader.FromFile(device3d, mouseDownFileName);
            disableTexture = D3D.TextureLoader.FromFile(device3d, disableFileName);
            Enable = true;
            //
            // set mouse device
            //
            try
            {
                MouseDevice = new DI.Device(DI.SystemGuid.Mouse);
                MouseDevice.SetDataFormat(DI.DeviceDataFormat.Mouse);
                MouseDevice.Acquire();
            }
            catch (DirectXException ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message, ex.Source);
            }
            finally
            {
                frm.MouseMove += new System.Windows.Forms.MouseEventHandler(frm_MouseMove);
            }
        }
Exemple #9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="gamepadInstanceGuid">The DirectInput device Guid</param>
 public PCGamepad(Guid gamepadInstanceGuid)
 {
     device = new DI.Device(gamepadInstanceGuid);
     device.SetDataFormat(DI.DeviceDataFormat.Joystick);
     device.Acquire();
     caps = device.Caps;
 }
 /// <summary>
 /// Inizializza un oggetto Tastiera
 /// </summary>
 /// <param name="Handle"></param>
 public Keyboard(Control Handle)
 {
     try
     {
         keyboard = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Keyboard);
         movement = new VertexData(0, 0, 0);
         if (LogiX_Engine.Device.PresentationParameters.Windowed)
         {
             keyboard.SetCooperativeLevel(Handle, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
         }
         else
         {
             keyboard.SetCooperativeLevel(Handle, CooperativeLevelFlags.Foreground | CooperativeLevelFlags.NonExclusive);
         }
         keyboard.SetDataFormat(DeviceDataFormat.Keyboard);
         keyboard.Acquire();
         correct = true;
     }
     catch
     {
         Error("OnCreateObject");
     }
 }
        /// <summary>
        ///		Prepares DirectInput for immediate mouse input.
        /// </summary>
        private void InitializeImmediateMouse()
        {
            // create the device
            mouseDevice = new DInput.Device(SystemGuid.Mouse);

            mouseDevice.Properties.AxisModeAbsolute = true;

            // set the device format so DInput knows this device is a mouse
            mouseDevice.SetDataFormat(DeviceDataFormat.Mouse);

            CooperativeLevelFlags excl = ownMouse ? CooperativeLevelFlags.Exclusive : CooperativeLevelFlags.NonExclusive;
            CooperativeLevelFlags background = (backgroundMouse && !ownMouse) ? CooperativeLevelFlags.Background : CooperativeLevelFlags.Foreground;

            // set cooperation level
            mouseDevice.SetCooperativeLevel(control.FindForm(), excl | background);

            // note: dont acquire yet, wait till capture
        }
        /// <summary>
        ///		Initializes DirectInput for immediate input.
        /// </summary>
        private void InitializeImmediateKeyboard()
        {
            // Create the device.
            keyboardDevice = new DInput.Device(SystemGuid.Keyboard);

            // grab the keyboard
            CooperativeLevelFlags excl = ownKeyboard ? CooperativeLevelFlags.Exclusive : CooperativeLevelFlags.NonExclusive;
            CooperativeLevelFlags background = (backgroundKeyboard && !ownKeyboard) ? CooperativeLevelFlags.Background : CooperativeLevelFlags.Foreground;

            keyboardDevice.SetCooperativeLevel(control.FindForm(), excl | background);

            // Set the data format to the keyboard pre-defined format.
            keyboardDevice.SetDataFormat(DeviceDataFormat.Keyboard);

            try {
                keyboardDevice.Acquire();
            }
            catch {
                throw new Exception("Unable to acquire a keyboard using DirectInput.");
            }
        }
        /// <summary>
        /// 
        /// </summary>
        private void InitializeBufferedMouse()
        {
            // create the device
            mouseDevice = new DInput.Device(SystemGuid.Mouse);

            mouseDevice.Properties.AxisModeAbsolute = true;

            // set the device format so DInput knows this device is a mouse
            mouseDevice.SetDataFormat(DeviceDataFormat.Mouse);

            // set the buffer size to use for input
            mouseDevice.Properties.BufferSize = BufferSize;

            CooperativeLevelFlags excl = ownMouse ? CooperativeLevelFlags.Exclusive : CooperativeLevelFlags.NonExclusive;
            CooperativeLevelFlags background = (backgroundMouse && !ownMouse) ? CooperativeLevelFlags.Background : CooperativeLevelFlags.Foreground;

            // set cooperation level
            mouseDevice.SetCooperativeLevel(control.FindForm(), excl | background);

            // note: dont acquire yet, wait till capture?
            //try {
            //    mouseDevice.Acquire();
            //} catch {
            //    throw new Exception("Unable to acquire a mouse using DirectInput.");
            //}
        }
        /// <summary>
        ///		Prepares DirectInput for non-immediate input capturing.
        /// </summary>
        private void InitializeBufferedKeyboard()
        {
            // create the device
            keyboardDevice = new DInput.Device(SystemGuid.Keyboard);

            // Set the data format to the keyboard pre-defined format.
            keyboardDevice.SetDataFormat(DeviceDataFormat.Keyboard);

            // grab the keyboard
            // For debugging, use the background flag so we don't lose input when we are in the debugger.
            // For release, use the foreground flag, so input to other apps doesn't show up here
            CooperativeLevelFlags excl = ownKeyboard ? CooperativeLevelFlags.Exclusive : CooperativeLevelFlags.NonExclusive;
            CooperativeLevelFlags background = (backgroundKeyboard && !ownKeyboard) ? CooperativeLevelFlags.Background : CooperativeLevelFlags.Foreground;

            keyboardDevice.SetCooperativeLevel(control.FindForm(), excl | background);

            // set the buffer size to use for input
            keyboardDevice.Properties.BufferSize = BufferSize;

            // note: dont acquire yet, wait till capture
            //try {
            //    keyboardDevice.Acquire();
            //}
            //catch {
            //    throw new Exception("Unable to acquire a keyboard using DirectInput.");
            //}
        }
Exemple #15
0
        private void InitInputDevices()
        {
            //keyboard

            keyboard = new Device(SystemGuid.Keyboard);
            if (keyboard == null)
            {
                System.Windows.Forms.MessageBox.Show("No keyboard found.!");
                throw new Exception("No keyboard found.");
            }

            //mouse
            mouse = new Device(SystemGuid.Mouse);

            if (mouse == null)
            {
                System.Windows.Forms.MessageBox.Show("No mouse found.!");
                throw new Exception("No mouse found.");
            }

            //mouse.Properties.AxisModeAbsolute = true;
            //set cooperation
            keyboard.SetCooperativeLevel(
                this.windowControl, flags);

            mouse.SetCooperativeLevel(
                this.windowControl, flags);

            mouse.SetDataFormat(DeviceDataFormat.Mouse);
            keyboard.SetDataFormat(DeviceDataFormat.Keyboard);

            try
            {
                keyboard.Properties.BufferSize = BUFFER_SIZE;
            }
            catch (Exception ex)
            {
                Logging.Logger.AddWarning("CHYBA V INPUTU! Nepodarilo se nastavit velikost bufferu. " + ex.ToString());
                throw;
            }

            //ziskat mys a klavesnici
            try
            {
                keyboard.Acquire();
                mouse.Acquire();
            }
            catch (InputException ex)
            {
                Logging.Logger.AddWarning("CHYBA V INPUTU! \nZkusim znovu ziskat input device jako sdileny\n" + ex.ToString());
                try
                {
                    keyboard.Unacquire();
                    mouse.Unacquire();
                    keyboard.SetCooperativeLevel(
                        this.windowControl,
                        CooperativeLevelFlags.NonExclusive |
                        CooperativeLevelFlags.Background);

                    mouse.SetCooperativeLevel(
                        this.windowControl,
                        CooperativeLevelFlags.NonExclusive |
                        CooperativeLevelFlags.Background);

                    keyboard.Acquire();
                    mouse.Acquire();
                }
                catch (InputException iex)
                {
                    Logging.Logger.AddError(" KRITICKA CHYBA V INPUTU!" + iex.ToString());
                    throw iex;
                }
            }
        }
        //privateなメソッド=====================
        /// <summary>
        /// デバイスの初期化
        /// </summary>
        static void Initialize()
        {
            //keyMap = PS2KeyMap;

            // DirectInputデバイスのリストを取得
            DInput.DeviceList controllers =
                DInput.Manager.GetDevices(
                    DInput.DeviceClass.GameControl,
                    DInput.EnumDevicesFlags.AllDevices);

            //Joystickのデバイスを作る器
            DInput.Device d;

            //取得したデバイスのリストをforeachして1つづつjoysticksに登録
            foreach (DInput.DeviceInstance i in controllers) {
                //デバイスの生成
                d = new DInput.Device(i.InstanceGuid);

                //各種フラグの設定。Backgroundだと第一引数のFormはnullでいい
                d.SetCooperativeLevel(null,
                    DInput.CooperativeLevelFlags.NonExclusive
                  | DInput.CooperativeLevelFlags.NoWindowsKey
                  | DInput.CooperativeLevelFlags.Background
                );

                //Joystickタイプのデータフォーマットを設定
                d.SetDataFormat(DInput.DeviceDataFormat.Joystick);

                //アナログスティックなどのAxis要素を持つDeviceObjectInstanceの出力レンジを設定
                foreach (DInput.DeviceObjectInstance oi in d.Objects) {
                    if ((oi.ObjectId & (int)DInput.DeviceObjectTypeFlags.Axis) != 0) {
                        d.Properties.SetRange(
                            DInput.ParameterHow.ById,
                            oi.ObjectId,
                            new DInput.InputRange(-1000, 1000));
                    }
                }

                //Axisの絶対位置モードを設定
                d.Properties.AxisModeAbsolute = true;

                //とりあえずデバイスを動かす
                try { d.Acquire(); }
                catch (Microsoft.DirectX.DirectXException) { }

                //作ったJoystickのDeviceをJoystickリストに追加
                joysticks.Add(d);

                //Joystickの状態を保持させる為のjsstatesを用意、とりあえず現在と以前の状態で2つ用意してみる
                //Geek:一個でよくね……?
                jsStates.Add(new DInput.JoystickState());
            }
        }
 /// <summary>
 /// Inizializza un oggetto Mouse
 /// </summary>
 /// <param name="Handle"></param>
 public Mouse(Control Handle)
 {
     try
     {
         my_mouse = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Mouse);
         if (LogiX_Engine.Device.PresentationParameters.Windowed)
         {
             my_mouse.SetCooperativeLevel(Handle, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
         }
         else
         {
             my_mouse.SetCooperativeLevel(Handle, CooperativeLevelFlags.Foreground | CooperativeLevelFlags.Exclusive);
         }
         my_mouse.SetDataFormat(DeviceDataFormat.Mouse);
         my_mouse.Acquire();
         correct = true;
     }
     catch
     {
         Error("OnCreateObject");
     }
 }