Ejemplo n.º 1
0
        private void KeyMappingtimerCode(object sender, EventArgs e)
        {
            if (sw.ElapsedMilliseconds > 1666)
            {
                Microsoft.DirectX.DirectInput.DeviceList devList =
                    Microsoft.DirectX.DirectInput.Manager.GetDevices(
                        Microsoft.DirectX.DirectInput.DeviceClass.GameControl,
                        Microsoft.DirectX.DirectInput.EnumDevicesFlags.AttachedOnly
                        );

                if (devList.Count != MainWindow.deviceControl.joyAssign.Length)
                {
                    mainWindow.ReloadDevices();
                    Reset();
                    getNeutralPosition();
                }

                sw.Reset();
                sw.Start();
            }

            KeyboardButtonMonitor();
            JoystickButtonMonitor();
            ShowAssignedStatus();
        }
Ejemplo n.º 2
0
 public static void EnumerateJosticks()
 {
     joystickList.Clear();
     DirectInput.DeviceList deviceList = DirectInput.Manager.GetDevices(DirectInput.DeviceClass.GameControl, DirectInput.EnumDevicesFlags.AttachedOnly);
     foreach (DirectInput.DeviceInstance di in deviceList)
     {
         joystickList.Add(di);
     }
 }
Ejemplo n.º 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());
            }
        }
Ejemplo n.º 4
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
Ejemplo n.º 5
0
        public InputDevice()
        {
            #region Step 3: Enumerate Devices.
            // ************************************************************************
            // Step 3: Enumerate Devices.
            //
            // Enumerate through devices according to the desired action map.
            // Devices are enumerated in a prioritized order, such that devices which
            // can best be mapped to the provided action map are returned first.
            // ************************************************************************
            #endregion

            // Setup the action format for actual gameplay
            DIActionFormat.ActionMapGuid = AppGuid;
            DIActionFormat.Genre         = (int)DInput.FlyingMilitary.Military;
            DIActionFormat.AxisMin       = -100;
            DIActionFormat.AxisMax       = 100;
            DIActionFormat.BufferSize    = 16;
            CreateActionMap(DIActionFormat.Actions);

            try
            {
                // Enumerate devices according to the action format
                DInput.DeviceList DevList = DInput.Manager.GetDevices(DIActionFormat, EnumDevicesBySemanticsFlags.AttachedOnly);
                foreach (SemanticsInstance instance in DevList)
                {
                    SetupDevice(instance.Device);
                }
            }
            catch
            {
                //	UserInterface.ShowException(ex, "EnumDevicesBySemantics");
            }

            // Start the input loop
            //		InputThread = new Thread(new ThreadStart(RunInputLoop));
            //		InputThread.Start();
        }