Esempio n. 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);
        }
Esempio n. 2
0
        private void InitInput()
        {
            //create keyboard device.
            keyboard = new Input.Device(Input.SystemGuid.Keyboard);
            if (keyboard == null)
            {
                MessageBox.Show("No keyboard found.");
            }
            keyboard.SetCooperativeLevel(
                this,
                Input.CooperativeLevelFlags.NonExclusive |
                Input.CooperativeLevelFlags.Background);
            keyboard.Acquire();

            //create mouse device.
            mouse = new Input.Device(Input.SystemGuid.Mouse);
            if (mouse == null)
            {
                MessageBox.Show("No mouse found.");
            }
            mouse.Properties.AxisModeAbsolute = false;
            mouse.SetCooperativeLevel(
                this,
                Input.CooperativeLevelFlags.NonExclusive |
                Input.CooperativeLevelFlags.Background);
            mouse.Acquire();
        }
Esempio n. 3
0
 /// <summary>
 /// Background thread runs this function in a loop reading SpacePilot state.
 /// </summary>
 void SpacePilotLoop()
 {
     while (true)
     {
         Thread.Sleep(20);
         try
         {
             // Poll the device for info.
             spacePilot.Poll();
             HandleSpacePilot();
         }
         catch (InputException inputex)
         {
             if ((inputex is NotAcquiredException) || (inputex is InputLostException))
             {
                 // Check to see if either the app
                 // needs to acquire the device, or
                 // if the app lost the device to another
                 // process.
                 try
                 {
                     // Acquire the device.
                     spacePilot.Acquire();
                 }
                 catch (InputException)
                 {
                     // Failed to acquire the device.
                     // This could be because the app
                     // doesn't have focus.
                     Thread.Sleep(1000);
                 }
             }
         }
     }
 }
Esempio n. 4
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();
        }
Esempio n. 5
0
        public void RestoreState(Form target)
        {
            keysDev.Dispose();
            mouseDev.Dispose();
            mouseDev = null;
            keysDev  = null;

            try
            {
                //create our mouse device
                mouseDev = new Device(SystemGuid.Mouse);
                mouseDev.SetCooperativeLevel(target, CooperativeLevelFlags.Foreground | CooperativeLevelFlags.Exclusive);
                mouseDev.Acquire();

                //create our keyboard device
                keysDev = new Device(SystemGuid.Keyboard);
                keysDev.Properties.BufferSize = 0;
                keysDev.SetCooperativeLevel(target, CooperativeLevelFlags.Foreground | CooperativeLevelFlags.Exclusive | CooperativeLevelFlags.NoWindowsKey);
                keysDev.Acquire();
            }
            catch (Exception)
            {
                MessageBox.Show("DirectInput Faild to Start (userinterface.vb). Outerspace will exit");
                target.Dispose();
                Application.Exit();
            }

            Cursor.Hide();
            needrestore = false;
        }
Esempio n. 6
0
 public KeyboardState KState()
 {
     try
     {
         return(keysDev.GetCurrentKeyboardState());
         //return the current key
     }
     catch
     {
         try
         {
             keysDev.Acquire();
             return(keysDev.GetCurrentKeyboardState());
             //try to regain the device if there is an input error
         }
         catch (InputException ex)
         {
             //catch an error while regaining the device
             if (ex is OtherApplicationHasPriorityException || ex is NotAcquiredException)
             {
                 return(null);
                 //if those excpetions occur return nothing as the device is not ready now
             }
             return(null);
         }
     }
 }
Esempio n. 7
0
        //For some reason this function has/creates either timing issues or
        public MouseState MState()
        {
            try
            {
                mouseStateData = mouseDev.CurrentMouseState;
                return(mouseStateData);
                //return the state of the mouse device
            }
            catch
            {
                //catch any error that occurs
                try
                {
                    mouseDev.Acquire();
                    mouseStateData = mouseDev.CurrentMouseState;
                    return(mouseStateData);
                    //try to get the device back after the error occurs
                }
                catch (InputException ex)
                {
                    //if regaining device failed then catch the error
                    if (ex is OtherApplicationHasPriorityException || ex is NotAcquiredException)
                    {
                        //check what type of input exception occured
                        return(new MouseState());
                        //return nothing as the MouseState
                    }

                    return(new MouseState());
                }
            }
        }
Esempio n. 8
0
        public c_input(IntPtr hwnd,bool window)
        {
            keyboard = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Keyboard);

            mouse = new Device(SystemGuid.Mouse);
            mouse.Properties.AxisModeAbsolute = false;
            if (window)
            {
                mouse.SetCooperativeLevel(hwnd, CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background);
                keyboard.SetCooperativeLevel(hwnd, CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background);

            }
            else
            {
                mouse.SetCooperativeLevel(hwnd, CooperativeLevelFlags.Foreground | CooperativeLevelFlags.Exclusive);
                keyboard.SetCooperativeLevel(hwnd, CooperativeLevelFlags.Exclusive | CooperativeLevelFlags.Foreground);

            }

            mouse.Acquire();
            keyboard.Acquire();

            this.X = 1024 / 2;
            this.Y = 768 / 2;
        }
Esempio n. 9
0
        private void InitializeAsKeyboard(ScreenAccess ParentForm, InputDeviceAccess.TypeOfDevices NewTypeOfDevice)
        {
            try
            {
                this.device = new DirectInput.Device(DirectInput.SystemGuid.Keyboard);
                this.device.SetCooperativeLevel
                (
                    ParentForm,
                    DirectInput.CooperativeLevelFlags.Background |
                    DirectInput.CooperativeLevelFlags.NonExclusive
                );
                device.Acquire();

                this._TypeOfDevice = NewTypeOfDevice;

                //Determine how many users are suited for this device
                this._DeviceUserMax = 2;

                // Get space in the keytable for the number of device users
                this.KeyTable = new System.Collections.Hashtable[this._DeviceUserMax];

                //record guid as used
                InputDeviceAccess.AssignedGuids.Add(this.device.DeviceInformation.InstanceGuid);
            }
            catch (Exception err)
            {
                throw err;
            }
        }
Esempio n. 10
0
 private void InitializeMouse()
 {
     mouse = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Mouse);
     mouse.SetCooperativeLevel(this, CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background);
     mouse.Properties.AxisModeAbsolute = false;
     mouse.Acquire();
 }
Esempio n. 11
0
        public TgcD3dInput(Control guiControl, Control panel3d)
        {
            this.guiControl = guiControl;
            this.panel3d = panel3d;

            //keyboard
            keyboardDevice = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Keyboard);
            keyboardDevice.SetCooperativeLevel(guiControl, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
            keyboardDevice.Acquire();

            //mouse
            mouseDevice = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Mouse);
            mouseDevice.SetCooperativeLevel(guiControl, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
            mouseDevice.Acquire();
            mouseIndex = 0;
            enableMouseFiltering = true;
            weightModifier = WEIGHT_MODIFIER;
            mouseX = 0;
            mouseY = 0;

            //Inicializar mouseMovement
            mouseMovement = new Vector2[2];
            for (int i = 0; i < mouseMovement.Length; i++)
            {
                mouseMovement[i] = new Vector2(0.0f, 0.0f);
            }

            //Inicializar historyBuffer
            historyBuffer = new Vector2[HISTORY_BUFFER_SIZE];
            for (int i = 0; i < historyBuffer.Length; i++)
            {
                historyBuffer[i] = new Vector2(0.0f, 0.0f);
            }

            //Inicializar ubicacion del cursor
            Point ceroToScreen = this.panel3d.PointToScreen(ceroPoint);
            Cursor.Position = new Point(ceroToScreen.X + panel3d.Width / 2, ceroToScreen.Y + panel3d.Height / 2);
            mouseInside = checkMouseInsidePanel3d();

            //Inicializar estados de teclas
            int[] keysArray = (int[])Enum.GetValues(typeof(Key));
            int maxKeyValue = keysArray[keysArray.Length - 1];
            previouskeyboardState = new bool[maxKeyValue];
            currentkeyboardState = new bool[maxKeyValue];
            for (int i = 0; i < maxKeyValue; i++)
            {
                previouskeyboardState[i] = false;
                currentkeyboardState[i] = false;
            }

            //Inicializar estados de botones del mouse
            previousMouseButtonsState = new bool[3];
            currentMouseButtonsState = new bool[previousMouseButtonsState.Length];
            for (int i = 0; i < previousMouseButtonsState.Length; i++)
            {
                previousMouseButtonsState[i] = false;
                currentMouseButtonsState[i] = false;
            }
        }
 // set up keyboard
 public void InitKeyboard()
 {
     keyboard = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Keyboard);
     keyboard.SetCooperativeLevel(
         this,
         CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
     keyboard.Acquire();
 }
Esempio n. 13
0
        private void Initialize()
        {
            try {
                //Common DirectX setup calls...
                PresentParameters presentParams = new PresentParameters();
                presentParams.Windowed               = true;
                presentParams.SwapEffect             = SwapEffect.Discard;
                presentParams.BackBufferFormat       = Format.Unknown;
                presentParams.AutoDepthStencilFormat = DepthFormat.D16;
                presentParams.EnableAutoDepthStencil = true;

                // Store the default adapter
                int         adapterOrdinal = D3D.Manager.Adapters.Default.Adapter;
                CreateFlags flags          = CreateFlags.SoftwareVertexProcessing;

                // Check to see if we can use a pure hardware device
                D3D.Caps caps = D3D.Manager.GetDeviceCaps(adapterOrdinal, D3D.DeviceType.Hardware);

                // Do we support hardware vertex processing?
                if (caps.DeviceCaps.SupportsHardwareTransformAndLight)
                {
                    // Replace the software vertex processing
                    flags = CreateFlags.HardwareVertexProcessing;
                }

                device              = new D3D.Device(0, D3D.DeviceType.Hardware, this, flags, presentParams);
                device.DeviceReset += new System.EventHandler(this.OnResetDevice);
                OnResetDevice(device, null);

                //Space Donuts setup
                donutTexture = TextureLoader.FromFile(device, MediaUtilities.FindFile(TileSetFileName), 1024, 1024,
                                                      1, 0, Format.A8R8G8B8, Pool.Managed, Filter.Point, Filter.Point, (unchecked ((int)0xff000000)));

                donutTileSet   = new TileSet(donutTexture, 0, 0, 6, 5, 32, 32);
                pyramidTileSet = new TileSet(donutTexture, 0, 384, 4, 10, 16, 16);
                sphereTileSet  = new TileSet(donutTexture, 0, 512, 2, 20, 8, 8);
                cubeTileSet    = new TileSet(donutTexture, 0, 544, 2, 20, 8, 8);
                shipTileSet    = new TileSet(donutTexture, 0, 576, 4, 10, 16, 16);
                nixiesTileSet  = new TileSet(donutTexture, 0, 832, 1, 14, 8, 8);
                bulletTileSet  = new TileSet(donutTexture, 304, 832, 1, 1, 8, 2);

                //set up DirectInput keyboard device...
                kbd = new DI.Device(SystemGuid.Keyboard);
                kbd.SetCooperativeLevel(this,
                                        DI.CooperativeLevelFlags.Background | DI.CooperativeLevelFlags.NonExclusive);
                kbd.Acquire();

                soundHandler = new SoundHandler(this);

                sm.OnCollisionDetected += new SpriteManager.HandleCollision(this.CollisionHandler);

                hrt.Start();
            }
            catch (DirectXException e) {
                Console.WriteLine("Exception is " + e.ErrorString);
                // Catch any errors and return a failure
            }
        }
Esempio n. 14
0
 public static void SetInputTo(Rendering.RenderForm form)
 {
     keyboard = new inp.Device(inp.SystemGuid.Keyboard);
     keyboard.SetCooperativeLevel(form, inp.CooperativeLevelFlags.NonExclusive | inp.CooperativeLevelFlags.Background);
     keyboard.Acquire();
     mouse = new inp.Device(inp.SystemGuid.Mouse);
     mouse.SetCooperativeLevel(form, inp.CooperativeLevelFlags.NonExclusive | inp.CooperativeLevelFlags.Background);
     mouse.Acquire();
 }
Esempio n. 15
0
 public void InitDevices()
 {
     mouse = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Mouse);
     mouse.Properties.AxisModeAbsolute = true;
     //mouse.Properties.
     //mouse.SetCooperativeLevel(this, CooperativeLevelFlags.Exclusive);
     mouse.SetCooperativeLevel(this, CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background);
     mouse.Acquire();
 }
        private void InitializeGraphics()
        {
            try {
                PresentParameters presentParams = new PresentParameters();
                presentParams.Windowed               = true;
                presentParams.SwapEffect             = SwapEffect.Discard;
                presentParams.BackBufferFormat       = Format.Unknown;
                presentParams.AutoDepthStencilFormat = DepthFormat.D16;
                presentParams.EnableAutoDepthStencil = true;

                // Store the default adapter
                int         adapterOrdinal = D3D.Manager.Adapters.Default.Adapter;
                CreateFlags flags          = CreateFlags.SoftwareVertexProcessing;

                // Check to see if we can use a pure hardware device
                D3D.Caps caps = D3D.Manager.GetDeviceCaps(adapterOrdinal, D3D.DeviceType.Hardware);

                // Do we support hardware vertex processing?
                if (caps.DeviceCaps.SupportsHardwareTransformAndLight)
                {
                    // Replace the software vertex processing
                    flags = CreateFlags.HardwareVertexProcessing;
                }

                // Do we support a pure device?
                if (caps.DeviceCaps.SupportsPureDevice)
                {
                    flags |= CreateFlags.PureDevice;
                }

                device              = new D3D.Device(0, D3D.DeviceType.Hardware, this, flags, presentParams);
                device.DeviceReset += new System.EventHandler(this.OnResetDevice);
                OnResetDevice(device, null);

                tileSheet = TextureLoader.FromFile(device, MediaUtilities.FindFile("donuts.bmp"), 1024, 1024,
                                                   1, 0, Format.A8R8G8B8, Pool.Managed, Filter.Point, Filter.Point, (unchecked ((int)0xff000000)));

                tileSet      = new TileSet(tileSheet, 0, 0, 6, 5, 32, 32);
                tilePosition = new Rectangle(tileSet.XOrigin, tileSet.YOrigin, tileSet.ExtentX * 2, tileSet.ExtentY * 2);

                //set up DirectInput keyboard device...
                kbd = new DI.Device(SystemGuid.Keyboard);
                kbd.SetCooperativeLevel(this,
                                        DI.CooperativeLevelFlags.Background | DI.CooperativeLevelFlags.NonExclusive);
                kbd.Acquire();

                //Set up DirectSound device and buffers
                snd = new DS.Device();
                snd.SetCooperativeLevel(this, DS.CooperativeLevel.Normal);
                bounce = new DS.SecondaryBuffer(MediaUtilities.FindFile("bounce.wav"), snd);

                hrt.Start();
            }
            catch (DirectXException) {
                // Catch any errors and return a failure
            }
        }
Esempio n. 17
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());
            }
        }
Esempio n. 18
0
        static public void InitKeyBoardCapture()
        {
            FreeDirectInput();
            CooperativeLevelFlags coopFlags;

            coopFlags    = CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive;
            mInputDevice = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Keyboard);
            mInputDevice.SetCooperativeLevel(mWindow, coopFlags);
            mInputDevice.Acquire();
        }
Esempio n. 19
0
        public static void InitDX()
        {
            PresentParameters present_params = new PresentParameters();
            present_params.Windowed = true;
            present_params.SwapEffect = SwapEffect.Discard;

            dxDevice = new Device(0, DeviceType.Hardware, Program.mainForm, CreateFlags.SoftwareVertexProcessing, present_params);
            Keyboard = new Microsoft.DirectX.DirectInput.Device(DirectInput.SystemGuid.Keyboard);
            Keyboard.Acquire();
            sprite = new Sprite(dxDevice);
        }
Esempio n. 20
0
        public void InitDevices()
        {
            mouse = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Mouse);

            mouse.Properties.AxisModeAbsolute = true;
            mouse.SetCooperativeLevel(this, CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background);
            mouse.Acquire();
            if (mouse == null)
            {
                throw new Exception("No mouse found.");
            }
        }
Esempio n. 21
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);
        }
Esempio n. 22
0
        /// <summary>
        /// Initializes the keyboard device to poll from.
        /// </summary>
        /// <param name="window">Window to poll keyboard from.</param>
        public void Initialize(Form window)
        {
            Dispose();
            _window = window;
            _device = new Device(SystemGuid.Keyboard);

            if (_device != null)
            {
                _device.SetCooperativeLevel(window.Handle,
                                            CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background);
                _device.Acquire();
            }
        }
Esempio n. 23
0
        } // onPaint().fim

        private void inicializarTeclado()
        {
            // Cria o dispositivo de gerenciamento do teclado
            teclado = new DirectInput.Device(DirectInput.SystemGuid.Keyboard);

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

            // Adquire o teclado
            teclado.Acquire();
        } // inicializarTeclado().fim
Esempio n. 24
0
        /// <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();
        }
Esempio n. 25
0
        /// <summary>
        /// Initializes the mouse device to poll from.
        /// </summary>
        /// <param name="window">Window to poll mouse from.</param>
        public void Initialize(Form window)
        {
            Dispose();
            _window = window;
            _device = new Device(SystemGuid.Mouse);

            if (_device != null)
            {
                _device.Properties.AxisModeAbsolute = false;
                _device.SetCooperativeLevel(window.Handle,
                                            CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background);
                _device.Acquire();
            }
        }
Esempio n. 26
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
Esempio n. 27
0
        } // onPaint().fim

        // [---
        private void inicializarMouse()
        {
            // Cria o dispositivo de gerenciamento do mouse
            mouse = new DirectInput.Device(DirectInput.SystemGuid.Mouse);

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

            // Configurado como false, os eixos terão valores relativos ao último frame
            mouse.Properties.AxisModeAbsolute = false;

            // Adquire o mouse
            mouse.Acquire();
        } // inicializarMouse().fim
Esempio n. 28
0
        private void timerPoll_Tick(object sender, EventArgs e)
        {
            try
            {
                deviceInput.Poll();
                deviceInputState = deviceInput.CurrentJoystickState;
            }
            catch (NotAcquiredException)
            {
                // try to reqcquire the device
                try { deviceInput.Acquire(); }
                catch (InputException iex) { Console.WriteLine(iex.Message); }
            }
            catch (InputException ex2) { Console.WriteLine(ex2.Message); }

            this.currentJoystickSmoothness = ((deviceInputState.Y / ((double)65536))) * 20 + 1;
            this.currentJoystickWidth      = (deviceInputState.X * 2 / ((double)65536) - 1.0) * 0.7;
        }
Esempio n. 29
0
        public bool InitializeGraphics()
        {
            Debug.WriteLine("InitializeGraphics()");
            //try
            //{
            Caps        caps = Direct3D.Manager.GetDeviceCaps(Direct3D.Manager.Adapters.Default.Adapter, Direct3D.DeviceType.Hardware);
            CreateFlags flags;

            if (caps.DeviceCaps.SupportsHardwareTransformAndLight)
            {
                flags = CreateFlags.HardwareVertexProcessing;
            }
            else
            {
                flags = CreateFlags.SoftwareVertexProcessing;
            }

            d3dpp.BackBufferFormat       = Format.Unknown;
            d3dpp.SwapEffect             = SwapEffect.Discard;
            d3dpp.Windowed               = true;
            d3dpp.EnableAutoDepthStencil = true;
            d3dpp.AutoDepthStencilFormat = DepthFormat.D16;
            d3dpp.PresentationInterval   = PresentInterval.Immediate;
            d3dpp.MultiSample            = MultiSampleType.FourSamples;

            device              = new Direct3D.Device(0, Direct3D.DeviceType.Hardware, this, flags, d3dpp);
            device.DeviceReset += new System.EventHandler(this.OnResetDevice);
            device.DeviceLost  += new System.EventHandler(this.OnLostDevice);
            //device.DeviceResizing += new System.ComponentModel.CancelEventHandler(this.OnResizeDevice);
            OnCreateDevice(device, null);

            dinputDevice = new DirectInput.Device(SystemGuid.Keyboard);
            dinputDevice.SetCooperativeLevel(this, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
            dinputDevice.Acquire();
            //}
            //catch (DirectXException e)
            //{
            //    MessageBox.Show(e.Message);
            //    return false;
            //}
            return(true);
        }
Esempio n. 30
0
        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);
            }
        }
Esempio n. 31
0
		/// <summary>
		/// 初始导演类
		/// </summary>
		/// <returns>是否初始化成功</returns>
		public bool Init()
		{
			try
			{
				//预设参数
				PresentParameters pp = new PresentParameters();
				pp.Windowed = true;
				pp.SwapEffect = SwapEffect.Discard;

				//创建设备
				d3dDevice = new Microsoft.DirectX.Direct3D.Device(
					0,
					Microsoft.DirectX.Direct3D.DeviceType.Hardware,
					this,
					CreateFlags.SoftwareVertexProcessing,
					pp
				);

				//input设备
				kbDevice = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Keyboard);
				kbDevice.SetCooperativeLevel(this, CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background);
				kbDevice.Acquire();

				//if (instance != null) return false;
				instance = this;

				//设置每帧时间间隔
				PerFrameTick = 1000.0f / 60;
				
				return true;
			}
			catch (DirectXException e)
			{
				ErrorReport.New(e);
				return false;
			}


		}
Esempio n. 32
0
        // ...4-02-06

        public userinterface(Form target)
        {
            mouseypos   = 300;
            mousexpos   = 400;
            mouseXdelta = 400;
            mouseYdelta = 300;

            try
            {
                targetform = target;
                mouseDev   = new Device(SystemGuid.Mouse);
                keysDev    = new Device(SystemGuid.Keyboard);
                keysDev.Properties.BufferSize = 0;

                if (OuterSpace.IsWindowMode)
                {
                    mouseDev.SetCooperativeLevel(target, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
                    keysDev.SetCooperativeLevel(target, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
                }
                else
                {
                    mouseDev.SetCooperativeLevel(target, CooperativeLevelFlags.Foreground | CooperativeLevelFlags.NonExclusive);
                    keysDev.SetCooperativeLevel(target, CooperativeLevelFlags.Foreground | CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.NoWindowsKey);
                }

                mouseDev.Acquire();
                keysDev.Acquire();
                mouseStateData = mouseDev.CurrentMouseState;
            }
            catch (Exception)
            {
                MessageBox.Show("DirectInput Failed to Start (userinterface.vb). Outerspace will exit");
                targetform.Dispose();
                Application.Exit();
            }

            //text_input = New textInput(target.Handle) ' ...4-02-06
        }
Esempio n. 33
0
        // ...4-02-06
        public userinterface(Form target)
        {
            mouseypos = 300;
            mousexpos = 400;
            mouseXdelta = 400;
            mouseYdelta = 300;

            try
            {
                targetform = target;
                mouseDev = new Device(SystemGuid.Mouse);
                keysDev = new Device(SystemGuid.Keyboard);
                keysDev.Properties.BufferSize = 0;

                if (OuterSpace.IsWindowMode)
                {
                    mouseDev.SetCooperativeLevel(target, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
                    keysDev.SetCooperativeLevel(target, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
                }
                else
                {
                    mouseDev.SetCooperativeLevel(target, CooperativeLevelFlags.Foreground | CooperativeLevelFlags.NonExclusive);
                    keysDev.SetCooperativeLevel(target, CooperativeLevelFlags.Foreground | CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.NoWindowsKey);
                }

                mouseDev.Acquire();
                keysDev.Acquire();
                mouseStateData = mouseDev.CurrentMouseState;
            }
            catch (Exception)
            {
                MessageBox.Show("DirectInput Failed to Start (userinterface.vb). Outerspace will exit");
                targetform.Dispose();
                Application.Exit();
            }

            //text_input = New textInput(target.Handle) ' ...4-02-06
        }
Esempio n. 34
0
        /// <summary>
        /// 初始导演类
        /// </summary>
        /// <returns>是否初始化成功</returns>
        public bool Init()
        {
            try
            {
                //预设参数
                PresentParameters pp = new PresentParameters();
                pp.Windowed   = true;
                pp.SwapEffect = SwapEffect.Discard;

                //创建设备
                d3dDevice = new Microsoft.DirectX.Direct3D.Device(
                    0,
                    Microsoft.DirectX.Direct3D.DeviceType.Hardware,
                    this,
                    CreateFlags.SoftwareVertexProcessing,
                    pp
                    );

                //input设备
                kbDevice = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Keyboard);
                kbDevice.SetCooperativeLevel(this, CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background);
                kbDevice.Acquire();

                //if (instance != null) return false;
                instance = this;

                //设置每帧时间间隔
                PerFrameTick = 1000.0f / 60;

                return(true);
            }
            catch (DirectXException e)
            {
                ErrorReport.New(e);
                return(false);
            }
        }
Esempio n. 35
0
 static void InitializeInput()
 {
     dIDevice = new DIDevice(SystemGuid.Keyboard);
     dIDevice.SetCooperativeLevel(m_GameWindow, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
     dIDevice.Acquire();
 }
Esempio n. 36
0
 public DirectInputKeyboard()
 {
     device = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Keyboard);
     device.Acquire();
 }
Esempio n. 37
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;
 }
Esempio n. 38
0
        /// <summary>
        /// Initializes the Keyboard and Mouse.
        /// </summary>
        /// <exception cref="KeyboardNotFoundException">DirectInput could not aquire Keyboard</exception>
        /// <exception cref="MouseNotFoundException">DirectInput could not aquire Mouse</exception>
        private void InitializeInputDevices()
        {
            keyboard = new DI.Device(DI.SystemGuid.Keyboard);
            if (keyboard == null) throw new KeyboardNotFoundException("No keyboard found.");

            mouse = new DI.Device(DI.SystemGuid.Mouse);
            if (mouse == null) throw new MouseNotFoundException("No mouse found.");

            keyboard.SetCooperativeLevel(this, DI.CooperativeLevelFlags.Background | DI.CooperativeLevelFlags.NonExclusive);
            keyboard.Acquire();

            mouse.SetCooperativeLevel(this, DI.CooperativeLevelFlags.NonExclusive | DI.CooperativeLevelFlags.Background);
            mouse.Acquire();
        }
        /// <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.");
            }
        }
Esempio n. 40
0
        public bool InitializeDirectInput()
        {
            try
            {
                diDevice = new DirectInput.Device(SystemGuid.Keyboard);
                diDevice.SetCooperativeLevel(this, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
                diDevice.Acquire();

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        private void Initialize()
        {
            try {
                //Common DirectX setup calls...
                PresentParameters presentParams = new PresentParameters();
                presentParams.Windowed = true;
                presentParams.SwapEffect = SwapEffect.Discard;
                presentParams.BackBufferFormat = Format.Unknown;
                presentParams.AutoDepthStencilFormat = DepthFormat.D16;
                presentParams.EnableAutoDepthStencil = true;

                // Store the default adapter
                int adapterOrdinal = D3D.Manager.Adapters.Default.Adapter;
                CreateFlags flags = CreateFlags.SoftwareVertexProcessing;

                // Check to see if we can use a pure hardware device
                D3D.Caps caps = D3D.Manager.GetDeviceCaps(adapterOrdinal, D3D.DeviceType.Hardware);

                // Do we support hardware vertex processing?
                if (caps.DeviceCaps.SupportsHardwareTransformAndLight)
                    // Replace the software vertex processing
                    flags = CreateFlags.HardwareVertexProcessing;

                device = new D3D.Device(0, D3D.DeviceType.Hardware, this, flags, presentParams);
                device.DeviceReset += new System.EventHandler(this.OnResetDevice);
                OnResetDevice(device, null);

                //Space Donuts setup
                donutTexture = TextureLoader.FromFile(device, MediaUtilities.FindFile(TileSetFileName), 1024, 1024,
                    1, 0,Format.A8R8G8B8, Pool.Managed, Filter.Point, Filter.Point, (unchecked((int)0xff000000)));

                donutTileSet = new TileSet(donutTexture, 0, 0, 6, 5, 32, 32);
                pyramidTileSet = new TileSet(donutTexture, 0, 384, 4, 10, 16, 16);
                sphereTileSet = new TileSet(donutTexture, 0, 512, 2, 20, 8, 8);
                cubeTileSet = new TileSet(donutTexture, 0, 544, 2, 20, 8, 8);
                shipTileSet = new TileSet(donutTexture, 0, 576, 4, 10, 16, 16);
                nixiesTileSet = new TileSet(donutTexture, 0, 832, 1, 14, 8, 8);
                bulletTileSet = new TileSet(donutTexture, 304, 832, 1, 1, 8, 2);

                //set up DirectInput keyboard device...
                kbd = new DI.Device(SystemGuid.Keyboard);
                kbd.SetCooperativeLevel(this,
                    DI.CooperativeLevelFlags.Background | DI.CooperativeLevelFlags.NonExclusive);
                kbd.Acquire();

                soundHandler = new SoundHandler(this);

                sm.OnCollisionDetected += new SpriteManager.HandleCollision(this.CollisionHandler);

                hrt.Start();
            }
            catch (DirectXException e) {
                Console.WriteLine("Exception is " + e.ErrorString);
                // Catch any errors and return a failure
            }
        }
Esempio n. 42
0
 /// <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");
     }
 }
Esempio n. 43
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());
            }
        }
Esempio n. 44
0
 static void InitializeInput()
 {
     dIDevice = new DIDevice(SystemGuid.Keyboard);
     dIDevice.SetCooperativeLevel(m_GameWindow, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
     dIDevice.Acquire();
 }
Esempio n. 45
0
        public void RestoreState(Form target)
        {
            keysDev.Dispose();
            mouseDev.Dispose();
            mouseDev = null;
            keysDev = null;

            try
            {
                //create our mouse device
                mouseDev = new Device(SystemGuid.Mouse);
                mouseDev.SetCooperativeLevel(target, CooperativeLevelFlags.Foreground | CooperativeLevelFlags.Exclusive);
                mouseDev.Acquire();

                //create our keyboard device
                keysDev = new Device(SystemGuid.Keyboard);
                keysDev.Properties.BufferSize = 0;
                keysDev.SetCooperativeLevel(target, CooperativeLevelFlags.Foreground | CooperativeLevelFlags.Exclusive | CooperativeLevelFlags.NoWindowsKey);
                keysDev.Acquire();
            }
            catch (Exception )
            {
                MessageBox.Show("DirectInput Faild to Start (userinterface.vb). Outerspace will exit");
                target.Dispose();
                Application.Exit();
            }

            Cursor.Hide();
            needrestore = false;
        }
Esempio n. 46
0
        private void deviceSelectButton_Click(object sender, System.EventArgs e)
        {
            threadRescanButton.Enabled = false;
            threadHookBox.Enabled = false;
            foreach(DeviceInstance di in Manager.GetDevices(
                DeviceClass.GameControl,
                EnumDevicesFlags.AttachedOnly))
            {
                if(((string)controlSelect.SelectedItem).CompareTo(di.InstanceName) == 0)
                {
                    hookyStick = new Device(di.InstanceGuid);
                    if(hookyStick == null)
                    {
                        throw new Exception("Cannot instantiate joystick");
                    }
                    //set cooperative level.
                    hookyStick.SetCooperativeLevel(
                        this,
                        CooperativeLevelFlags.Exclusive | CooperativeLevelFlags.Background);
                    System.Diagnostics.Debug.WriteLine("Starting");
                    //Set joystick axis ranges.
                    foreach(DeviceObjectInstance doi in hookyStick.Objects)
                    {

                        if((doi.ObjectId & (int)DeviceObjectTypeFlags.Axis) != 0)
                        {
                            hookyStick.Properties.SetRange(
                                ParameterHow.ById,
                                doi.ObjectId,
                                new InputRange(-5000,5000));
                        }
                        else if((doi.ObjectId & (int)DeviceObjectTypeFlags.AbsoluteAxis) != 0)
                        {
                            hookyStick.Properties.SetRange(
                                ParameterHow.ById,
                                doi.ObjectId,
                                new InputRange(-5000,5000));
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine(doi.ToString());
                        }
                    }

                    //Set joystick axis mode absolute.
                    hookyStick.Properties.AxisModeAbsolute = true;
                    //Acquire joystick for capturing.
                    hookyStick.Acquire();
                }
            }
            threadRescanButton.Enabled = true;
        }
Esempio n. 47
0
 /// <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");
     }
 }
 public void InitializeKeyboard()
 {
     keyb = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Keyboard);
     keyb.SetCooperativeLevel(this, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
     keyb.Acquire();
 }
Esempio n. 49
0
        public TgcD3dInput(Control guiControl, Control panel3d)
        {
            this.guiControl = guiControl;
            this.panel3d    = panel3d;

            //keyboard
            keyboardDevice = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Keyboard);
            keyboardDevice.SetCooperativeLevel(guiControl, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
            keyboardDevice.Acquire();

            //mouse
            mouseDevice = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Mouse);
            mouseDevice.SetCooperativeLevel(guiControl, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
            mouseDevice.Acquire();
            mouseIndex           = 0;
            enableMouseFiltering = true;
            weightModifier       = WEIGHT_MODIFIER;
            mouseX = 0;
            mouseY = 0;

            //Inicializar mouseMovement
            mouseMovement = new Vector2[2];
            for (int i = 0; i < mouseMovement.Length; i++)
            {
                mouseMovement[i] = new Vector2(0.0f, 0.0f);
            }

            //Inicializar historyBuffer
            historyBuffer = new Vector2[HISTORY_BUFFER_SIZE];
            for (int i = 0; i < historyBuffer.Length; i++)
            {
                historyBuffer[i] = new Vector2(0.0f, 0.0f);
            }

            //Inicializar ubicacion del cursor
            Point ceroToScreen = this.panel3d.PointToScreen(ceroPoint);

            Cursor.Position = new Point(ceroToScreen.X + panel3d.Width / 2, ceroToScreen.Y + panel3d.Height / 2);
            mouseInside     = checkMouseInsidePanel3d();


            //Inicializar estados de teclas
            int[] keysArray   = (int[])Enum.GetValues(typeof(Key));
            int   maxKeyValue = keysArray[keysArray.Length - 1];

            previouskeyboardState = new bool[maxKeyValue];
            currentkeyboardState  = new bool[maxKeyValue];
            for (int i = 0; i < maxKeyValue; i++)
            {
                previouskeyboardState[i] = false;
                currentkeyboardState[i]  = false;
            }

            //Inicializar estados de botones del mouse
            previousMouseButtonsState = new bool[3];
            currentMouseButtonsState  = new bool[previousMouseButtonsState.Length];
            for (int i = 0; i < previousMouseButtonsState.Length; i++)
            {
                previousMouseButtonsState[i] = false;
                currentMouseButtonsState[i]  = false;
            }
        }
Esempio n. 50
0
        private void InitInput()
        {
            //create keyboard device.
            keyboard = new Input.Device(Input.SystemGuid.Keyboard);
            if (keyboard == null) {
                MessageBox.Show("No keyboard found.");
            }
            keyboard.SetCooperativeLevel(
            this,
            Input.CooperativeLevelFlags.NonExclusive |
            Input.CooperativeLevelFlags.Background);
            keyboard.Acquire();

            //create mouse device.
            mouse = new Input.Device(Input.SystemGuid.Mouse);
            if (mouse == null) {
                MessageBox.Show("No mouse found.");
            }
            mouse.Properties.AxisModeAbsolute = false;
            mouse.SetCooperativeLevel(
            this,
            Input.CooperativeLevelFlags.NonExclusive |
            Input.CooperativeLevelFlags.Background);
            mouse.Acquire();
        }
Esempio n. 51
0
        private void controlSelect_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if(ffActuator != null)	ffActuator.Unacquire();
            feedbackAmountSlider.Enabled = false;
            objectGUIDValue.Enabled = false;
            xmlQueryButton.Enabled = false;
            foreach(DeviceInstance di in Manager.GetDevices(DeviceClass.All, EnumDevicesFlags.ForceFeeback))
            {
                if(((string)controlSelect.SelectedItem).CompareTo(di.InstanceName) == 0)
                {
                    ffActuator = new Device(di.InstanceGuid);
                    if(ffActuator == null)
                    {
                        throw new Exception("Cannot instantiate joystick");
                    }
                    //set cooperative level.
                    ffActuator.SetCooperativeLevel(
                        this,
                        CooperativeLevelFlags.Exclusive | CooperativeLevelFlags.Background);

                    //Set axis mode absolute.
                    ffActuator.Properties.AxisModeAbsolute = true;

                    //Acquire joystick for capturing.
                    ffActuator.Acquire();

                    //Configure axes
                    foreach(DeviceObjectInstance doi in ffActuator.Objects)
                    {

                        //Set axes ranges.
                        if((doi.ObjectId & (int)DeviceObjectTypeFlags.Axis) != 0)
                        {
                            ffActuator.Properties.SetRange(
                                ParameterHow.ById,
                                doi.ObjectId,
                                new InputRange(-5000,5000));
                        }

                        int[] temp;

                        // Get info about first two FF axii on the device
                        if ((doi.Flags & (int)ObjectInstanceFlags.Actuator) != 0)
                        {
                            if (forceAxes != null)
                            {
                                temp = new int[forceAxes.Length + 1];
                                forceAxes.CopyTo(temp,0);
                                forceAxes = temp;
                            }
                            else
                            {
                                forceAxes = new int[1];
                            }

                            // Store the offset of each axis.
                            forceAxes[forceAxes.Length - 1] = doi.Offset;
                            if (forceAxes.Length == 2)
                            {
                                break;
                            }

                            string path =
                                @"C:\temp\force.ffe";
                            EffectList el = null;
                            el = ffActuator.GetEffects(path,FileEffectsFlags.ModifyIfNeeded);
                            EffectObject feo = null;
                            foreach(FileEffect fe in el)
                            {
                                constantVibrate = fe.EffectStruct;
                                feo = new EffectObject(
                                      fe.EffectGuid,
                                      fe.EffectStruct,
                                      ffActuator);
                                try
                                {
                                    feo.Download();
                                }
                                catch(Exception ex)
                                {
                                    throw new Exception("Could not download force feedback effect file.", ex);
                                }
                                eo = feo;
                                break;
                            }
                            constantVibrate.Constant.Magnitude = 0;
                            eo.SetParameters(constantVibrate, EffectParameterFlags.TypeSpecificParams);
                            eo.Download();
                            eo.Start(1);
                            feedbackAmountSlider.Enabled = true;
                            objectGUIDValue.Enabled = true;
                            xmlQueryButton.Enabled = true;
                        }
                    }
                    break;
                }
            }
        }
        private void InitializeGraphics()
        {
            try {
                PresentParameters presentParams = new PresentParameters();
                presentParams.Windowed = true;
                presentParams.SwapEffect = SwapEffect.Discard;
                presentParams.BackBufferFormat = Format.Unknown;
                presentParams.AutoDepthStencilFormat = DepthFormat.D16;
                presentParams.EnableAutoDepthStencil = true;

                // Store the default adapter
                int adapterOrdinal = D3D.Manager.Adapters.Default.Adapter;
                CreateFlags flags = CreateFlags.SoftwareVertexProcessing;

                // Check to see if we can use a pure hardware device
                Caps caps = D3D.Manager.GetDeviceCaps(adapterOrdinal, D3D.DeviceType.Hardware);

                // Do we support hardware vertex processing?
                if (caps.DeviceCaps.SupportsHardwareTransformAndLight)
                    // Replace the software vertex processing
                    flags = CreateFlags.HardwareVertexProcessing;

                // Do we support a pure device?
                if (caps.DeviceCaps.SupportsPureDevice)
                    flags |= CreateFlags.PureDevice;

                device = new D3D.Device(0, D3D.DeviceType.Hardware, this, flags, presentParams);
                device.DeviceReset += new System.EventHandler(this.OnResetDevice);
                OnResetDevice(device, null);

                tileSheet = TextureLoader.FromFile(device, MediaUtilities.FindFile("donuts.bmp"), 1024, 1024,
                    1, 0,Format.A8R8G8B8, Pool.Managed, Filter.Point, Filter.Point, (unchecked((int)0xff000000)));
                //Uncomment these lines to see the spite border areas
                //				donutTexture = TextureLoader.FromFile(device, MediaUtilities.FindFile("donuts.bmp"), 1024, 1024,
                //					1, 0,Format.A8R8G8B8, Pool.Managed, Filter.Point, Filter.Point, 0);

                tileSet = new TileSet(tileSheet, 0, 0, 6, 5, 32, 32);
                tilePosition = new Rectangle(tileSet.XOrigin, tileSet.YOrigin,tileSet.ExtentX*2, tileSet.ExtentY*2);

                //set up DirectInput keyboard device...
                kbd = new DI.Device(SystemGuid.Keyboard);
                kbd.SetCooperativeLevel(this,
                    DI.CooperativeLevelFlags.Background | DI.CooperativeLevelFlags.NonExclusive );
                kbd.Acquire();

                hrt.Start();

            }
            catch (DirectXException) {
                // Catch any errors and return a failure
            }
        }