Esempio n. 1
0
		public static void Initialize()
		{
			if (dinput == null)
				dinput = new DirectInput();

			Devices = new List<GamePad>();

			foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
			{
				Console.WriteLine("joydevice: {0} `{1}`", device.InstanceGuid, device.ProductName);

				if (device.ProductName.Contains("XBOX 360"))
					continue; // Don't input XBOX 360 controllers into here; we'll process them via XInput (there are limitations in some trigger axes when xbox pads go over xinput)

				var joystick = new Joystick(dinput, device.InstanceGuid);
				joystick.SetCooperativeLevel(GlobalWin.MainForm.Handle, CooperativeLevel.Background | CooperativeLevel.Nonexclusive);
				foreach (DeviceObjectInstance deviceObject in joystick.GetObjects())
				{
					if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
						joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000);
				}
				joystick.Acquire();

				GamePad p = new GamePad(device.InstanceName, device.InstanceGuid, joystick);
				Devices.Add(p);
			}
		}
Esempio n. 2
0
        /// 
        /// Construct, attach the joystick
        /// 
        public SimpleJoystick()
        {
            DirectInput dinput = new DirectInput();

            // Search for device
            foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                // Create device
                try
                {
                    Joystick = new Joystick(dinput, device.InstanceGuid);
                    break;
                }
                catch (DirectInputException)
                {
                }
            }

            if (Joystick == null)
                throw new Exception("No joystick found");

            foreach (DeviceObjectInstance deviceObject in Joystick.GetObjects())
            {
                if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                    Joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-100, 100);
            }

            // Acquire sdevice
            Joystick.Acquire();
        }
Esempio n. 3
0
        private Joystick GetJoystick()
        {
            var directInput = new DirectInput();
            var form = new Form();

            foreach (var device in directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                var controller = new Joystick(directInput, device.InstanceGuid);
                controller.SetCooperativeLevel(form.Handle, CooperativeLevel.Exclusive | CooperativeLevel.Background);

                var retries = 0;
                while (controller.Acquire().IsFailure)
                {
                    retries++;
                    if (retries > 500)
                        throw new Exception("Couldnt acquire SlimDX stick");
                }

                if (controller.Information.InstanceName.Contains("PPJoy"))
                {

                    foreach (DeviceObjectInstance deviceObject in controller.GetObjects())
                    {
                        if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                            controller.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000);
                    }

                    return controller;
                }
            }

            return null;
        }
Esempio n. 4
0
 public Mouse(DirectInput input, IntPtr wndHandle)
 {
     mMouse = new SlimDX.DirectInput.Mouse(input);
     mMouse.SetCooperativeLevel(wndHandle, CooperativeLevel.Background | CooperativeLevel.Nonexclusive);
     mMouse.Acquire();
     State = mMouse.GetCurrentState();
 }
Esempio n. 5
0
        public MainController()
        {
            var directInput = new DirectInput();
            LogicState = new LogicState();

            foreach (var deviceInstance in directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                try
                {
                    gamepad = new Joystick(directInput, deviceInstance.InstanceGuid);
                    gamepad.SetCooperativeLevel(Parent, CooperativeLevel.Exclusive | CooperativeLevel.Foreground);
                    break;
                }
                catch (DirectInputException) { }
            }

            if (gamepad == null)
                return;

            foreach (var deviceObject in gamepad.GetObjects())
            {
                if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                    gamepad.GetObjectPropertiesById((int) deviceObject.ObjectType).SetRange(-1000, 1000);
            }

            gamepad.Acquire();
        }
Esempio n. 6
0
 public static Joystick[] AllJoysticks()
 {
     using(DirectInput directInput = new DirectInput()) {
         IList<DeviceInstance> devices = directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly);
         return devices.Select(x => new Joystick(x.InstanceGuid)).ToArray();
     }
 }
        public NesVSUnisystemDIPKeyboardConnection(IntPtr handle, IInputSettingsVSUnisystemDIP settings)
        {
            DirectInput di = new DirectInput();
            keyboard = new Keyboard(di);
            keyboard.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground);

            if (settings.CreditServiceButton != "")
                CreditServiceButton = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.CreditServiceButton);
            if (settings.DIPSwitch1 != "")
                DIPSwitch1 = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.DIPSwitch1);
            if (settings.DIPSwitch2 != "")
                DIPSwitch2 = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.DIPSwitch2);
            if (settings.DIPSwitch3 != "")
                DIPSwitch3 = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.DIPSwitch3);
            if (settings.DIPSwitch4 != "")
                DIPSwitch4 = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.DIPSwitch4);
            if (settings.DIPSwitch5 != "")
                DIPSwitch5 = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.DIPSwitch5);
            if (settings.DIPSwitch6 != "")
                DIPSwitch6 = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.DIPSwitch6);
            if (settings.DIPSwitch7 != "")
                DIPSwitch7 = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.DIPSwitch7);
            if (settings.DIPSwitch8 != "")
                DIPSwitch8 = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.DIPSwitch8);
            if (settings.CreditLeftCoinSlot != "")
                CreditLeftCoinSlot = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.CreditLeftCoinSlot);
            if (settings.CreditRightCoinSlot != "")
                CreditRightCoinSlot = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.CreditRightCoinSlot);
            NesEmu.EMUShutdown += NesEmu_EMUShutdown;
        }
Esempio n. 8
0
        /// <summary>
        /// Získání prvního gamepadu, ketrý je připojený k počítači
        /// </summary>
        /// <returns>zařízení</returns>
        /// <exception>Pokud se nepodařilo najít žádné funkční zařízení</exception>
        private SlimDX.DirectInput.Joystick getGamepad()
        {
            dinput = new DirectInput();
            SlimDX.DirectInput.Joystick gamepad;
            string errorMessage = "Nebylo nalezeno žádné vnější ovládací zařízení.";

            foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                try
                {
                    gamepad = new SlimDX.DirectInput.Joystick(dinput, device.InstanceGuid);
                    gamepad.Acquire();

                    foreach (DeviceObjectInstance deviceObject in gamepad.GetObjects())
                    {
                        if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                        {
                            gamepad.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-100, 100);
                        }
                    }
                    return gamepad;
                }
                catch (DirectInputException e)
                {
                    dinput.Dispose();
                    errorMessage = e.Message;
                }
            }
            dinput.Dispose();
            throw new DirectInputException(errorMessage);
        }
        public NesJoypadPcJoystickConnection(IntPtr handle, string guid, IInputSettingsJoypad settings)
        {
            DirectInput di = new DirectInput();
            joystick = new Joystick(di, Guid.Parse(guid));
            joystick.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground);

            if (settings.ButtonUp != "")
                KeyUp = ParseKey(settings.ButtonUp);
            if (settings.ButtonDown != "")
                KeyDown = ParseKey(settings.ButtonDown);
            if (settings.ButtonLeft != "")
                KeyLeft = ParseKey(settings.ButtonLeft);
            if (settings.ButtonRight != "")
                KeyRight = ParseKey(settings.ButtonRight);
            if (settings.ButtonStart != "")
                KeyStart = ParseKey(settings.ButtonStart);
            if (settings.ButtonSelect != "")
                KeySelect = ParseKey(settings.ButtonSelect);
            if (settings.ButtonA != "")
                KeyA = ParseKey(settings.ButtonA);
            if (settings.ButtonB != "")
                KeyB = ParseKey(settings.ButtonB);
            if (settings.ButtonTurboA != "")
                KeyTurboA = ParseKey(settings.ButtonTurboA);
            if (settings.ButtonTurboB != "")
                KeyTurboB = ParseKey(settings.ButtonTurboB);
        }
        public BasicInput(IntPtr controlHandle)
        {
            DirectInput directInput = new DirectInput();
            CooperativeLevel cooperativeLevel = CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground | CooperativeLevel.NoWinKey;

            try
            {
                _keyboardDevice = new Device<KeyboardState>(directInput, SystemGuid.Keyboard);
                _keyboardDevice.SetCooperativeLevel(controlHandle, cooperativeLevel);
                _keyboardDevice.Properties.BufferSize = 16;
            }
            catch (DirectInputException e)
            {
                MessageBox.Show(e.Message);
                return;
            }

            try
            {
                _mouseDevice = new Device<MouseState>(directInput, SystemGuid.Mouse);
                _mouseDevice.SetCooperativeLevel(controlHandle, cooperativeLevel);
                _mouseDevice.Properties.BufferSize = 16;
            }
            catch (DirectInputException e)
            {
                MessageBox.Show(e.Message);
                return;
            }
        }
Esempio n. 11
0
        public static Joystick[] GetSticks(DirectInput input)
        {
            List<SlimDX.DirectInput.Joystick> sticks = new List<SlimDX.DirectInput.Joystick>(); // Creates the list of joysticks connected to the computer via USB.
            foreach (DeviceInstance device in input.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                // Creates a joystick for each game device in USB Ports
                try
                {
                    Joystick stick = new SlimDX.DirectInput.Joystick(input, device.InstanceGuid);
                    stick.Acquire();

                    // Gets the joysticks properties and sets the range for them.
                    foreach (DeviceObjectInstance deviceObject in stick.GetObjects())
                    {
                        if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                            stick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-100, 100);
                    }

                    // Adds how ever many joysticks are connected to the computer into the sticks list.
                    sticks.Add(stick);
                }
                catch (DirectInputException)
                {
                }
            }
            return sticks.ToArray();
        }
Esempio n. 12
0
 public static int NumJoysticks()
 {
     DirectInput direct = new DirectInput();
     int count = direct.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly).Count;
     direct.Dispose();
     return count;
 }
Esempio n. 13
0
        public GamepadReader()
        {
            Buttons = _buttons;
            Analogs = _analogs;

            _dinput = new DirectInput();

            var devices = _dinput.GetDevices (DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly);
            if (devices.Count < 1) {
                throw new IOException ("GamepadReader could not find a connected gamepad.");
            }
            _joystick = new Joystick (_dinput, devices[0].InstanceGuid);

            foreach (var obj in _joystick.GetObjects()) {
                if ((obj.ObjectType & ObjectDeviceType.Axis) != 0) {
                    _joystick.GetObjectPropertiesById ((int)obj.ObjectType).SetRange (-RANGE, RANGE);
                }
            }

            if (_joystick.Acquire().IsFailure) {
                throw new IOException ("Connected gamepad could not be acquired.");
            }

            _timer = new DispatcherTimer ();
            _timer.Interval = TimeSpan.FromMilliseconds (TIMER_MS);
            _timer.Tick += tick;
            _timer.Start ();
        }
Esempio n. 14
0
        public Joystick()
        {
            var di = new DirectInput();

            // Get the first device
            try
            {
                var device = di.GetDevices()[0];
                joystick = new SlimDX.DirectInput.Joystick(di, device.InstanceGuid);
            }
            catch (IndexOutOfRangeException e)
            {
                Console.WriteLine("No devices: {0}", e.Message);
                Environment.Exit(1);
            }
            catch (DirectInputException e)
            {
                Console.WriteLine(e.Message);
                Environment.Exit(1);
            }

            foreach (DeviceObjectInstance deviceObject in joystick.GetObjects())
            {
                if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                    joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000);
            }

            joystick.Acquire();
        }
Esempio n. 15
0
    public void ConnectJoysticks()
    {
        // make sure that DirectInput has been initialized
        DirectInput dinput = new DirectInput();
        // search for devices
        foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
        {
            // create the device
            try
            {
                JoysticksConnected.AddLast(new Joystick(dinput, device.InstanceGuid));
            }
            catch (DirectInputException)
            {
                Utils.Log("Warning: Joystick did not init (DirectInputException)");
            }
        }

        Utils.Log("joysticks connected: " +  JoysticksConnected.Count);

        //Set the axises of all of the analog sticks, then claim the joystick
        foreach (Joystick joystick in JoysticksConnected)
        {
            foreach (DeviceObjectInstance deviceObject in joystick.GetObjects())
            {
                if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                    joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-AxisRange, AxisRange);
            }
            joystick.Acquire();
        }
    }
Esempio n. 16
0
        private Joystick[] obtenerDispositivos()
        {
            var sticks = new List<SlimDX.DirectInput.Joystick>();
            DirectInput dinput = new DirectInput();
            foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                // crear los dispositivos
                try
                {
                    var stick = new SlimDX.DirectInput.Joystick(dinput, device.InstanceGuid);
                    stick.Acquire();

                    foreach (DeviceObjectInstance deviceObject in stick.GetObjects())
                    {
                        if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                            stick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000);
                    }

                    sticks.Add(stick);
                }
                catch (DirectInputException)
                {
                }
            }
            return sticks.ToArray();
        }
        public DirectInputManager()
        {
            var directInput = new DirectInput();

            // Prefer a Driving device but make do with fallback to a Joystick if we have to
            var deviceInstance = FindAttachedDevice(directInput, DeviceType.Driving);
            if (null == deviceInstance)
                deviceInstance = FindAttachedDevice(directInput, DeviceType.Joystick);
            if (null == deviceInstance)
                throw new Exception("No Driving or Joystick devices attached.");
            joystickType = (DeviceType.Driving == deviceInstance.Type ? JoystickTypes.Driving : JoystickTypes.Joystick);

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

            // Data for both Driving and Joystick device types is received via Joystick
            joystick = new Joystick(directInput, deviceInstance.InstanceGuid);
            IntPtr consoleWindowHandle = GetConsoleWindow();
            if (IntPtr.Zero != consoleWindowHandle)
            {
                CooperativeLevel cooperativeLevel = CooperativeLevel.Background | CooperativeLevel.Nonexclusive;
                Log.Spew("Console window cooperative level: " + cooperativeLevel);
                if (!joystick.SetCooperativeLevel(consoleWindowHandle, cooperativeLevel).IsSuccess)
                    throw new Exception("Failed to set cooperative level for DirectInput device in console window.");
            }
            var result = joystick.Acquire();
            if (!result.IsSuccess)
                throw new Exception("Failed to acquire DirectInput device.");

            Log.Spew("Joystick acquired.");
        }
        public NesVSUnisystemDIPJoystickConnection(IntPtr handle, string guid, IInputSettingsVSUnisystemDIP settings)
        {
            DirectInput di = new DirectInput();
            joystick = new Joystick(di, Guid.Parse(guid));
            joystick.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground);

            if (settings.CreditServiceButton != "")
                CreditServiceButton = ParseKey(settings.CreditServiceButton);
            if (settings.DIPSwitch1 != "")
                DIPSwitch1 = ParseKey(settings.DIPSwitch1);
            if (settings.DIPSwitch2 != "")
                DIPSwitch2 = ParseKey(settings.DIPSwitch2);
            if (settings.DIPSwitch3 != "")
                DIPSwitch3 = ParseKey(settings.DIPSwitch3);
            if (settings.DIPSwitch4 != "")
                DIPSwitch4 = ParseKey(settings.DIPSwitch4);
            if (settings.DIPSwitch5 != "")
                DIPSwitch5 = ParseKey(settings.DIPSwitch5);
            if (settings.DIPSwitch6 != "")
                DIPSwitch6 = ParseKey(settings.DIPSwitch6);
            if (settings.DIPSwitch7 != "")
                DIPSwitch7 = ParseKey(settings.DIPSwitch7);
            if (settings.DIPSwitch8 != "")
                DIPSwitch8 = ParseKey(settings.DIPSwitch8);
            if (settings.CreditLeftCoinSlot != "")
                CreditLeftCoinSlot = ParseKey(settings.CreditLeftCoinSlot);
            if (settings.CreditRightCoinSlot != "")
                CreditRightCoinSlot = ParseKey(settings.CreditRightCoinSlot);
            NesEmu.EMUShutdown += NesEmu_EMUShutdown;
        }
Esempio n. 19
0
 public Keyboard()
 {
     var directInput = new DirectInput();
     mKeyboard = new SlimDX.DirectInput.Keyboard(directInput);
     mKeyboard.Acquire();
     mState = new KeyboardState();
 }
        public NesJoypadPcKeyboardConnection(IntPtr handle, IInputSettingsJoypad settings)
        {
            DirectInput di = new DirectInput();
            keyboard = new Keyboard(di);
            keyboard.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground);

            if (settings.ButtonUp != "")
                KeyUp = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.ButtonUp);
            if (settings.ButtonDown != "")
                KeyDown = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.ButtonDown);
            if (settings.ButtonLeft != "")
                KeyLeft = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.ButtonLeft);
            if (settings.ButtonRight != "")
                KeyRight = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.ButtonRight);
            if (settings.ButtonStart != "")
                KeyStart = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.ButtonStart);
            if (settings.ButtonSelect != "")
                KeySelect = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.ButtonSelect);
            if (settings.ButtonA != "")
                KeyA = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.ButtonA);
            if (settings.ButtonB != "")
                KeyB = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.ButtonB);
            if (settings.ButtonTurboA != "")
                KeyTurboA = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.ButtonTurboA);
            if (settings.ButtonTurboB != "")
                KeyTurboB = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.ButtonTurboB);
        }
Esempio n. 21
0
        public Joystick()
        {
            var di = new DirectInput();

            foreach (var device in di.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                try
                {
                    joystick = new SlimDX.DirectInput.Joystick(di, device.InstanceGuid);
                    Connected = true;
                    joystick.RunControlPanel();
                    break;
                }
                catch
                {
                }
            }

            /*foreach (DeviceObjectInstance deviceObject in joystick.GetObjects())
            {
                if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                {
                    joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000);
                }
            }*/

            if (Connected)
                joystick.Acquire();
        }
Esempio n. 22
0
 public RuntimeDriver()
 {
     try
     {
         this.directInput = new DirectInput();
     }
     catch { }
 }
Esempio n. 23
0
 public static IList<ControllerDevice> Available()
 {
     var dinput = new DirectInput();
     return
         dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)
               .Select(di => new ControllerDevice {Guid = di.InstanceGuid, Name = di.InstanceName})
               .ToList();
 }
Esempio n. 24
0
		private string _GetDeviceName(Guid instanceGuid)
		{
			using (DirectInput directInput = new DirectInput()) {
				IList<DeviceInstance> devices = directInput.GetDevices(DeviceClass.GameController,
				                                                       DeviceEnumerationFlags.AttachedOnly);
				DeviceInstance deviceInstance = devices.FirstOrDefault(x => x.InstanceGuid == instanceGuid);
				return (deviceInstance != null) ? deviceInstance.InstanceName : null;
			}
		}
Esempio n. 25
0
		public static void Initialize()
		{
			if (dinput == null) 
				dinput = new DirectInput();

			if (keyboard == null || keyboard.Disposed)
				keyboard = new Keyboard(dinput);
			keyboard.SetCooperativeLevel(GlobalWin.MainForm.Handle, CooperativeLevel.Background | CooperativeLevel.Nonexclusive);
			keyboard.Properties.BufferSize = 8;
		}
Esempio n. 26
0
		public static void Initialize(IntPtr parent)
		{
			if (dinput == null) 
				dinput = new DirectInput();

			if (keyboard == null || keyboard.Disposed)
				keyboard = new Keyboard(dinput);
			keyboard.SetCooperativeLevel(parent, CooperativeLevel.Background | CooperativeLevel.Nonexclusive);
			keyboard.Properties.BufferSize = 8;
		}
Esempio n. 27
0
 public static void Init(Form mainWindow)
 {
     var dinput = new DirectInput();
     _keyboard = new Keyboard(dinput);
     _keyboard.Acquire();
     _mouse = new Mouse(dinput);
     _mouse.Acquire();
     dinput.Dispose();
     dinput = null;
 }
Esempio n. 28
0
 public ControllerManager(Control _handle)
     : base(BUS_CLASS_GUID)
 {
     directInput = new DirectInput();
     devices = new ControllerDevice[4];
     handle = _handle;
     ds4locks[0] = new object();
     ds4locks[1] = new object();
     ds4locks[2] = new object();
     ds4locks[3] = new object();
 }
        private void attemptJoystickConnect(object state)
        {
            // Initialize DirectInput
            var directInput = new DirectInput();

            // Find a Joystick Guid
            var joystickGuid = Guid.Empty;

            foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices))
            {
                joystickGuid = deviceInstance.InstanceGuid;
            }

            // If Joystick not found, throws an error
            if (joystickGuid == Guid.Empty)
            {
                return;
            }
            else
            {
                // Instantiate the joystick
                joystick = new Joystick(directInput, joystickGuid);

                Debug.WriteLine("Found Joystick/Gamepad with GUID: {0}", joystickGuid);

                // Query all suported ForceFeedback effects
                var allEffects = joystick.GetEffects();
                foreach (var effectInfo in allEffects)
                {
                    Debug.WriteLine("Effect available {0}", effectInfo.Name);
                }

                // Set BufferSize in order to use buffered data.
                joystick.Properties.BufferSize = 128;

                // Acquire the joystick
                joystick.Acquire();

                // Poll events from joystick
                pollTimer = new System.Threading.Timer(getJoystickData, null, 0, 20);

                isDeviceAttached = true;

                // Stop connection timer
                if (connectTimer != null)
                {
                    connectTimer.Dispose();
                }
                if (OnConnectionEvent != null)
                {
                    OnConnectionEvent(this, new joystickEventArgs(X, Y));
                }
            }
        }
Esempio n. 30
0
        // コンストラクタ

        public CInputJoystick(IntPtr hWnd, DeviceInstance di, DirectInput directInput)
        {
            this.e入力デバイス種別 = E入力デバイス種別.Joystick;
            this.GUID      = di.InstanceGuid.ToString();
            this.ID        = 0;
            try
            {
                this.devJoystick = new Joystick(directInput, di.InstanceGuid);
                this.devJoystick.SetCooperativeLevel(hWnd, CooperativeLevel.Foreground | CooperativeLevel.Exclusive);
                this.devJoystick.Properties.BufferSize = 32;
                Trace.TraceInformation(this.devJoystick.Information.InstanceName + "を生成しました。");
            }
            catch (DirectInputException)
            {
                if (this.devJoystick != null)
                {
                    this.devJoystick.Dispose();
                    this.devJoystick = null;
                }
                Trace.TraceError(this.devJoystick.Information.InstanceName, new object[] { " の生成に失敗しました。" });
                throw;
            }
            foreach (DeviceObjectInstance instance in this.devJoystick.GetObjects())
            {
                if ((instance.ObjectType & ObjectDeviceType.Axis) != ObjectDeviceType.All)
                {
                    this.devJoystick.GetObjectPropertiesById((int)instance.ObjectType).SetRange(-1000, 1000);
                    this.devJoystick.GetObjectPropertiesById((int)instance.ObjectType).DeadZone = 5000;                                 // 50%をデッドゾーンに設定
                    // 軸をON/OFFの2値で使うならこれで十分
                }
            }
            try
            {
                this.devJoystick.Acquire();
            }
            catch (DirectInputException e)
            {
                Trace.TraceError(e.ToString());
                Trace.TraceError("例外が発生しましたが処理を継続します。 (5658360e-2745-4c5c-ab2d-ff82287d3e8a)");
            }

            for (int i = 0; i < this.bButtonState.Length; i++)
            {
                this.bButtonState[i] = false;
            }
            for (int i = 0; i < this.nPovState.Length; i++)
            {
                this.nPovState[i] = -1;
            }

            //this.timer = new CTimer( CTimer.E種別.MultiMedia );

            this.list入力イベント = new List <STInputEvent>(32);
        }
Esempio n. 31
0
        public override object CreateGlobal()
        {
            var directInput = new DirectInput();
            var handle      = Process.GetCurrentProcess().MainWindowHandle;

            devices = new List <Device>();
            Directory.CreateDirectory("joysticks".FreePiePath());
            string pathlog = @"joysticks\joy.log".FreePiePath();

            File.Delete(pathlog);

            XDocument xdoc;

            xdoc = new XDocument(new XElement("Devices"));
            //xdoc.Save(pathlog);

            // fin tkz
            var      diDevices = directInput.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly);
            XElement el        = xdoc.Element("Devices");

            el.Add(
                new XElement("Joysticks_Connected",
                             new XAttribute("NBR", diDevices == null ? 0: diDevices.Count()),
                             from j in diDevices
                             select new XElement("IDENT",
                                                 new XAttribute("id", diDevices.IndexOf(j)),
                                                 new XAttribute("Name", j.InstanceName.TrimEnd('\0'))))
                );
            xdoc.Save(pathlog);
            var creator = new Func <DeviceInstance, JoystickGlobal>(d =>
            {
                var controller = new Joystick(directInput, d.InstanceGuid);
                controller.SetCooperativeLevel(handle, CooperativeLevel.Exclusive | CooperativeLevel.Background);
                controller.Acquire();

                var device = new Device(controller, pathlog, devices.Count());
                devices.Add(device);
                return(new JoystickGlobal(device));
            });

            //return new GlobalIndexer<JoystickGlobal, int, string>(index => creator(diDevices[index]), index => creator(diDevices.Single(di => di.InstanceName.Contains(index))));

            //example watch the pov's of dual thrustmaster T16000M joysticks
            //diagnostics.watch(joystick["T.16000M", 0].pov[0])
            //diagnostics.watch(joystick["T.16000M", 1].pov[0])

            //or specify the first device found same syntax as before (the index is optional and defaults to 0)
            //diagnostics.watch(joystick["T.16000M"].pov[0])
            return(new GlobalIndexer <JoystickGlobal, int, string>(intIndex => creator(diDevices[intIndex]), (strIndex, idx) =>
            {
                var d = diDevices.Where(di => di.InstanceName.TrimEnd('\0') == strIndex).ToArray();
                return d.Length > 0 && d.Length > idx ? creator(d[idx]) : null;
            }));
        }
Esempio n. 32
0
 public ControllerManager(Control _handle)
     : base(BUS_CLASS_GUID)
 {
     directInput = new DirectInput();
     devices     = new ControllerDevice[4];
     handle      = _handle;
     ds4locks[0] = new object();
     ds4locks[1] = new object();
     ds4locks[2] = new object();
     ds4locks[3] = new object();
 }
        public static List <uint> GetDevices()
        {
            int amount = new DirectInput().GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly).Count;
            var result = new List <uint>(amount);

            for (uint i = 0; i < amount; i++)
            {
                result.Add(i);
            }
            return(result);
        }
        /// <summary> データを読み取っている場合、それを停止する </summary>
        public void Stop()
        {
            LogOutput.Instance.Write("Stop Reading Gamepad");
            _joystick?.Dispose();
            _joystick = null;

            _directInput?.Dispose();
            _directInput = null;

            _joystickReady = false;
        }
Esempio n. 35
0
 // TODO: Zapper with "Wild Gun Man" - The Gang Mode is not working !
 public ZapperConnecter(IntPtr handle, int winPosX, int winPosY, int videoW, int videoH)
 {
     this.scanlinesCount = 240;
     this.videoW = videoW;
     this.videoH = videoH;
     this.winPosX = winPosX;
     this.winPosY = winPosY;
     DirectInput di = new DirectInput();
     mouse = new Mouse(di);
     mouse.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground);
 }
        public IList <DeviceInstance> Available()
        {
            IList <DeviceInstance> result = new List <DeviceInstance>();
            DirectInput            dinput = new DirectInput();

            foreach (DeviceInstance di in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                result.Add(di);
            }
            return(result);
        }
Esempio n. 37
0
        public JoystickInput(string name, Guid guid, string codeId)
        {
            this.name   = name;
            this.guid   = guid;
            this.codeId = codeId;

            DirectInput directInput = new DirectInput();

            joy = new Joystick(directInput, guid);
            joy.Properties.BufferSize = 64;
            joy.Acquire();
        }
Esempio n. 38
0
        static void input_test()
        {
            // Initialize DirectInput
            var directInput = new DirectInput();

            // Find a Joystick Guid
            var joystickGuid = Guid.Empty;

            foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad,
                                                                  DeviceEnumerationFlags.AllDevices))
            {
                joystickGuid = deviceInstance.InstanceGuid;
            }

            // If Gamepad not found, look for a Joystick
            if (joystickGuid == Guid.Empty)
            {
                foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick,
                                                                      DeviceEnumerationFlags.AllDevices))
                {
                    joystickGuid = deviceInstance.InstanceGuid;
                }
            }

            // If Joystick not found, throws an error
            if (joystickGuid == Guid.Empty)
            {
                Console.WriteLine("No joystick/Gamepad found.");
                Console.Read();
                Environment.Exit(1);
            }

            // Instantiate the joystick
            var joystick = new Joystick(directInput, joystickGuid);

            Console.WriteLine("Found Joystick/Gamepad with GUID: {0}", joystickGuid);

            // Query all suported ForceFeedback effects
            var allEffects = joystick.GetEffects();

            foreach (var effectInfo in allEffects)
            {
                Console.WriteLine("Effect available {0}", effectInfo.Name);
            }

            // Set BufferSize in order to use buffered data.
            joystick.Properties.BufferSize = 128;

            // Acquire the joystick
            joystick.Acquire();

            // Poll events from joysti
        }
Esempio n. 39
0
        /// <summary>
        /// Set up the inputs for running in arcade board mode
        /// </summary>
        private void SetupArcadeInputs()
        {
            this.Buzzers = new List <Buzzer>();

            this.arcadeJoystick = null;

            // Initialize DirectInput
            var directInput = new DirectInput();

            // Find a Joystick Guid
            var joystickGuid = Guid.Empty;

            foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices))
            {
                joystickGuid = deviceInstance.InstanceGuid;
            }

            if (joystickGuid != Guid.Empty)
            {
                this.arcadeJoystick = new Joystick(directInput, joystickGuid);
                this.arcadeJoystick.Properties.BufferSize = 128;
                this.arcadeJoystick.Acquire();

                int buzzerCount = 0;

                var buzzer = new Buzzer();

                // Figure out how many players there are
                foreach (var joystickObject in this.arcadeJoystick.GetObjects())
                {
                    if (joystickObject.Name != null && joystickObject.Name.Contains("Button"))
                    {
                        buzzerCount++;
                    }
                }

                this.lblBuzzersDetected.Text = buzzerCount.ToString();
                buzzer.BuzzerIndex           = 0;
                buzzer.AddPlayers(buzzerCount);
                this.Buzzers.Add(buzzer);
            }

            if (this.arcadeBuzzTimer != null)
            {
                this.arcadeBuzzTimer.Stop();
                this.arcadeBuzzTimer.Dispose();
            }

            this.arcadeBuzzTimer          = new System.Timers.Timer();
            this.arcadeBuzzTimer.Elapsed += new ElapsedEventHandler(this.HandleArcadeBuzzes);
            this.arcadeBuzzTimer.Interval = 1;
            this.arcadeBuzzTimer.Start();
        }
Esempio n. 40
0
        // TODO: Zapper with "Wild Gun Man" - The Gang Mode is not working !
        public ZapperConnecter(IntPtr handle, int winPosX, int winPosY, int videoW, int videoH)
        {
            this.scanlinesCount = 240;
            this.videoW         = videoW;
            this.videoH         = videoH;
            this.winPosX        = winPosX;
            this.winPosY        = winPosY;
            DirectInput di = new DirectInput();

            mouse = new Mouse(di);
            mouse.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground);
        }
Esempio n. 41
0
        public MainWindow()
        {
            InitializeComponent();
            Dispatcher.ShutdownStarted += Dispatcher_ShutdownStarted;

            safetyStatus = Resources["Status"] as SafetyStatus;

            directInput = new DirectInput();
            udpClient   = new UdpClient();
            InitJoystick();
            InitTimer();
        }
Esempio n. 42
0
        public DeviceInformationCollection GetDevices(VjdStat[] status)
        {
            using (var input = new DirectInput())
            {
                var deviceInstances = input.GetDevices().Where(w => w.ProductGuid.Equals(VJoyProductGuid)).ToList();

                var result = new DeviceInformationCollection();
                for (short i = 0; i < 16; i++)
                {
                    var deviceId = Convert.ToUInt32(i);

                    try
                    {
                        var joystick = new vJoy();

                        if (!joystick.isVJDExists(deviceId))
                        {
                            continue;
                        }

                        var joyStatus = joystick.GetVJDStatus(deviceId);

                        if (!status.Contains(joyStatus))
                        {
                            continue;
                        }

                        foreach (var device in deviceInstances.Select(s => new Joystick(input, s.InstanceGuid)))
                        {
                            var objects = device.GetObjects(DeviceObjectTypeFlags.All);

                            var first = objects.FirstOrDefault(fd => fd.ReportId.Equals(i));

                            if (first == null)
                            {
                                continue;
                            }

                            result.Add(first.ReportId, device.Information.ProductName.TrimEnd('\0'), device.Information.InstanceGuid,
                                       joyStatus);

                            break;
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }

                return(result);
            }
        }
Esempio n. 43
0
        public void Refresh()
        {
            var devices     = DirectInput.GetDevices(DeviceClass.All, DeviceEnumerationFlags.AttachedOnly);
            var controllers = new List <IController>(devices.Count);

            for (var x = 0; x < devices.Count; x++)
            {
                controllers.Add(AcquireController(devices[x], x));
            }

            Controllers = controllers.ToArray();
        }
Esempio n. 44
0
        internal bool Initialize(SystemConfiguration configuration, IntPtr windowsHandle)
        {
            // Screen the screen size which will be used for positioning the mouse cursor.
            _ScreenWidth  = configuration.Width;
            _ScreenHeight = configuration.Height;

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

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

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

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

            // Now acquire the keyboard.
            try
            {
                _Keyboard.Acquire();
            }
            catch (Exception)
            {
#if !DEBUG
                throw;
#endif
            }

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

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

            // Now acquire the mouse.
            try
            {
                _Mouse.Acquire();
            }
            catch (Exception)
            {
#if !DEBUG
                throw;
#endif
            }

            return(true);
        }
Esempio n. 45
0
        public Controller(IntPtr Owner)
        {
            hWnd           = Owner;
            currentDevice  = null;
            Name           = "NA";
            full_scale     = 100;
            ChannelMapping = null;

            CHANNEL = new int[(int)ChannelNumber.NUM_CHANNELS];

            directInput = new DirectInput();
        }
 public static IDevice Create(object device, DirectInput di, Guid g)
 {
     if (device is Joystick)
     {
         return(new vJoystick(di, g));
     }
     if (device is Mouse)
     {
         return(new vMouse(di));
     }
     return(new vJoystick(di, g));   //defult
 }
Esempio n. 47
0
        public Input()
        {
            _directInput = new DirectInput();

            try
            {
                Result result;

                _keyboard = new Keyboard(_directInput);

                IntPtr handle = Engine.GameEngine.Window;

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

                _mouse = new Mouse(_directInput);

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

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

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

                Engine.GameEngine.Exception.Exceptions.Add(new ExceptionData("worked", "worked", "worked"));
            }
            catch (DirectInputException e)
            {
                Engine.GameEngine.Exception.Exceptions.Add(new ExceptionData(e.Message, e.Source, e.StackTrace));
            }
            catch (Exception e)
            {
                Engine.GameEngine.Exception.Exceptions.Add(new ExceptionData(e.Message, e.Source, e.StackTrace));
            }
            finally
            {
                Dispose();
            }
        }
Esempio n. 48
0
        public JoystickManager(DriverStationState st)
        {
            m_state     = st;
            m_di        = new DirectInput();
            m_joysticks = new Dictionary <int, Joystick>();

            SearchForJoysticks();

            m_monitor = true;
            m_thread  = new Thread(new ThreadStart(MonitorJoysticks));
            m_thread.Start();
        }
Esempio n. 49
0
        // コンストラクタ

        public CInputJoystick(IntPtr hWnd, DeviceInstance di, DirectInput directInput)
        {
            this.eInputDeviceType = EInputDeviceType.Joystick;
            this.GUID             = di.InstanceGuid.ToString();
            this.ID = 0;
            try
            {
                this.devJoystick = new Joystick(directInput, di.InstanceGuid);
                this.devJoystick.SetCooperativeLevel(hWnd, CooperativeLevel.Foreground | CooperativeLevel.Exclusive);
                this.devJoystick.Properties.BufferSize = 32;
                Trace.TraceInformation(this.devJoystick.Information.InstanceName + "を生成しました。");
                this.strDeviceName = this.devJoystick.Information.InstanceName;
            }
            catch
            {
                if (this.devJoystick != null)
                {
                    this.devJoystick.Dispose();
                    this.devJoystick = null;
                }
                Trace.TraceError(this.devJoystick.Information.InstanceName, new object[] { " の生成に失敗しました。" });
                throw;
            }
            foreach (DeviceObjectInstance instance in this.devJoystick.GetObjects())
            {
                if ((instance.ObjectId.Flags & DeviceObjectTypeFlags.Axis) != DeviceObjectTypeFlags.All)
                {
                    this.devJoystick.GetObjectPropertiesById(instance.ObjectId).Range    = new InputRange(-1000, 1000);
                    this.devJoystick.GetObjectPropertiesById(instance.ObjectId).DeadZone = 5000;                            // 50%をデッドゾーンに設定
                    // 軸をON/OFFの2値で使うならこれで十分
                }
            }
            try
            {
                this.devJoystick.Acquire();
            }
            catch
            {
            }

            for (int i = 0; i < this.bButtonState.Length; i++)
            {
                this.bButtonState[i] = false;
            }
            for (int i = 0; i < this.nPovState.Length; i++)
            {
                this.nPovState[i] = -1;
            }

            //this.timer = new CTimer( CTimer.E種別.MultiMedia );

            this.listInputEvent = new List <STInputEvent>(32);
        }
Esempio n. 50
0
 // The bulk of the clean-up code is implemented in Dispose(bool)
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         UnInitDeviceDetector();
         if (Manager != null)
         {
             Manager.Dispose();
             Manager = null;
         }
     }
 }
        public static InputDeviceKeyboard CreateKeyboard()      // direct keyboard make, not part of elite UI
        {
            DirectInput dinput = new DirectInput();

            foreach (DeviceInstance di in dinput.GetDevices(DeviceClass.Keyboard, DeviceEnumerationFlags.AttachedOnly))
            {
                InputDeviceKeyboard k = new InputDeviceKeyboard(dinput, di);
                return(k);
            }

            return(null);
        }
Esempio n. 52
0
        public void InitializeDirectInput()
        {
            directInput = new DirectInput();

            keyboard = new Keyboard(directInput);
            mouse    = new Mouse(directInput);

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

            mainForm.Click += OnMouseClick;
        }
        public NesVSUnisystemDIPJoystickConnection(IntPtr handle, string guid, IInputSettingsVSUnisystemDIP settings)
        {
            DirectInput di = new DirectInput();

            joystick = new Joystick(di, Guid.Parse(guid));
            joystick.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground);

            if (settings.CreditServiceButton != "")
            {
                CreditServiceButton = ParseKey(settings.CreditServiceButton);
            }
            if (settings.DIPSwitch1 != "")
            {
                DIPSwitch1 = ParseKey(settings.DIPSwitch1);
            }
            if (settings.DIPSwitch2 != "")
            {
                DIPSwitch2 = ParseKey(settings.DIPSwitch2);
            }
            if (settings.DIPSwitch3 != "")
            {
                DIPSwitch3 = ParseKey(settings.DIPSwitch3);
            }
            if (settings.DIPSwitch4 != "")
            {
                DIPSwitch4 = ParseKey(settings.DIPSwitch4);
            }
            if (settings.DIPSwitch5 != "")
            {
                DIPSwitch5 = ParseKey(settings.DIPSwitch5);
            }
            if (settings.DIPSwitch6 != "")
            {
                DIPSwitch6 = ParseKey(settings.DIPSwitch6);
            }
            if (settings.DIPSwitch7 != "")
            {
                DIPSwitch7 = ParseKey(settings.DIPSwitch7);
            }
            if (settings.DIPSwitch8 != "")
            {
                DIPSwitch8 = ParseKey(settings.DIPSwitch8);
            }
            if (settings.CreditLeftCoinSlot != "")
            {
                CreditLeftCoinSlot = ParseKey(settings.CreditLeftCoinSlot);
            }
            if (settings.CreditRightCoinSlot != "")
            {
                CreditRightCoinSlot = ParseKey(settings.CreditRightCoinSlot);
            }
            NesEmu.EMUShutdown += NesEmu_EMUShutdown;
        }
Esempio n. 54
0
        public void Dispose()
        {
            Mouse?.Unacquire();
            Mouse?.Dispose();
            Mouse = null;

            Keyboard.Unacquire();
            Keyboard.Dispose();
            Keyboard = null;

            DirectInput.Dispose();
        }
Esempio n. 55
0
    public void LoadPersistedData(string name, bool visualise = false)
    {
        /// Reseting the ID for every new deserialized item so the ids match the original ids.
        this.UI.classVisualisation.Reset();

        CubeInfo[] infos = GetAllSavedCubes();

        CubeInfo info = infos.FirstOrDefault(x => x.Name == name);

        if (info == null)
        {
            Debug.Log("No info with the given name!!!");
            return;
        }

        List <ClassVisualisation.MethodAndParameterNodes[]> methodInfoWithParamInfo = new List <ClassVisualisation.MethodAndParameterNodes[]>();

        /// Creating and regestering the class nodes
        for (int i = 0; i < info.ClassInfos.Length; i++)
        {
            ClassInfo cin      = info.ClassInfos[i];
            Type      type     = Assembly.GetExecutingAssembly().GetType(cin.Name);
            Vector3   position = cin.Position;

            var spellClass = this.UI.classVisualisation.GenerateClassVisualisation(this.UI.classVisualisation.GenerateNodeData(type), position, out Node one);

            this.UI.connTracker.RegisterClassNameForPersistence(new ClassTracking {
                Name = type.FullName, node = one
            }, info.Name);

            methodInfoWithParamInfo.Add(spellClass);
        }
        ///...

        List <InputCanvas.InputElements> inputs = new List <InputCanvas.InputElements>();

        /// Establish the DirectInputs
        List <ResultCanvas.VariableInput> variablesForDisplay = new List <ResultCanvas.VariableInput>();

        for (int i = 0; i < info.directInputs.Length; i++)
        {
            DirectInput DI = info.directInputs[i];

            /// CONSTANT
            if (DI.Name == null)
            {
                var cnst = this.UI.inputCanvas.CreateInputCanvas(DI.Value, DI.ID, this.UI, false);
                this.UI.connTracker.RegisterDirectInput(new DirectInput(DI.ID, null, DI.Value), info.Name);
                inputs.Add(cnst);
            }
            else /// VARIABLE
            {
                var var = this.UI.inputCanvas.CreateInputCanvas(default, DI.ID, this.UI, true, DI.Name);
Esempio n. 56
0
        public ControllerManager()
        {
            var directInput = new DirectInput();

            joystickIds = new List <Guid>();

            foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad,
                                                                  DeviceEnumerationFlags.AllDevices))
            {
                joystickIds.Add(deviceInstance.InstanceGuid);
            }
        }
Esempio n. 57
0
        public NesVSUnisystemDIPKeyboardConnection(IntPtr handle, IInputSettingsVSUnisystemDIP settings, EmulationState emulationState)
        {
            DirectInput di = new DirectInput();

            keyboard = new Keyboard(di);
            keyboard.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground);

            if (settings.CreditServiceButton != "")
            {
                CreditServiceButton = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.CreditServiceButton);
            }
            if (settings.DIPSwitch1 != "")
            {
                DIPSwitch1 = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.DIPSwitch1);
            }
            if (settings.DIPSwitch2 != "")
            {
                DIPSwitch2 = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.DIPSwitch2);
            }
            if (settings.DIPSwitch3 != "")
            {
                DIPSwitch3 = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.DIPSwitch3);
            }
            if (settings.DIPSwitch4 != "")
            {
                DIPSwitch4 = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.DIPSwitch4);
            }
            if (settings.DIPSwitch5 != "")
            {
                DIPSwitch5 = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.DIPSwitch5);
            }
            if (settings.DIPSwitch6 != "")
            {
                DIPSwitch6 = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.DIPSwitch6);
            }
            if (settings.DIPSwitch7 != "")
            {
                DIPSwitch7 = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.DIPSwitch7);
            }
            if (settings.DIPSwitch8 != "")
            {
                DIPSwitch8 = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.DIPSwitch8);
            }
            if (settings.CreditLeftCoinSlot != "")
            {
                CreditLeftCoinSlot = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.CreditLeftCoinSlot);
            }
            if (settings.CreditRightCoinSlot != "")
            {
                CreditRightCoinSlot = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.CreditRightCoinSlot);
            }
            emulationState.EMUShutdown += NesEmu_EMUShutdown;
        }
        public FanatecExtControl(FanatecExtension ext, SimFeedbackExtensionFacade facade)
        {
            fanatecExt        = ext;
            simFeedbackFacade = facade;
            // Initialize DirectInput
            directInput = new DirectInput();

            InitializeComponent();

            ListInputDevices();
            trackBarMouseSpeed.Value = (int)(mouseSpeed * 10.0);
        }
Esempio n. 59
0
        public JoystickViewModel(IVehicleComponent vehicleComponent)
        {
            VehicleComponent = vehicleComponent;
            Messenger.Default.Register <VehicleSelected>(this, VehicleSelectedAction);
            SenderTimer = new DispatcherTimer {
                Interval = new TimeSpan(0, 0, 0, 0, 1000 / 12)
            };
            UiThread = new DispatcherTimer {
                Interval = new TimeSpan(0, 0, 0, 0, 1000 / 12)
            };

            UiThread.Tick += UiThread_Tick;
            UiThread.Start();
            _joystick = new MAVLink.mavlink_rc_channels_override_t();
            // make sure that DirectInput has been initialized
            var dinput = new DirectInput();

            // search for devices
            foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                // create the device
                try
                {
                    joystick = new Joystick(dinput, device.InstanceGuid);

                    break;
                }
                catch (DirectInputException exception)
                {
                    Logger.Error("JoystickViewModel", exception);
                }
            }

            if (joystick == null)
            {
                //MessageBox.Show("There are no joysticks attached to the system.");
                return;
            }
            foreach (DeviceObjectInstance deviceObject in joystick.GetObjects())
            {
                if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                {
                    joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(MinJoystickRange, MaxJoystickRange);
                }
            }
            Equalisers = new ObservableCollection <Equaliser>();
            for (int i = 0; i < 12; i++)
            {
                Equalisers.Add(new Equaliser {
                    Id = i + 1, Channel = 1, Value = 0, IsChecked = false, Receiver = 0
                });
            }
        }
Esempio n. 60
0
        private void InitiallizeGamePad()
        {
            // Initialize DirectInput
            var directInput = new DirectInput();

            // Find a Joystick Guid
            var joystickGuid = Guid.Empty;

            foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad,
                                                                  DeviceEnumerationFlags.AllDevices))
            {
                joystickGuid = deviceInstance.InstanceGuid;
            }

            // If Gamepad not found, look for a Joystick
            if (joystickGuid == Guid.Empty)
            {
                foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick,
                                                                      DeviceEnumerationFlags.AllDevices))
                {
                    joystickGuid = deviceInstance.InstanceGuid;
                }
            }

            // If Joystick not found, throws an error
            if (joystickGuid == Guid.Empty)
            {
                MessageBox.Show("HopScotch Matte nicht gefunden! ");
            }
            else
            {
                // Instantiate the joystick
                joystick = new Joystick(directInput, joystickGuid);

                Console.WriteLine("Found Joystick/Gamepad with GUID: {0}", joystickGuid);

                // Query all suported ForceFeedback effects
                var allEffects = joystick.GetEffects();
                foreach (var effectInfo in allEffects)
                {
                    Console.WriteLine("Effect available {0}", effectInfo.Name);
                }

                // Set BufferSize in order to use buffered data.
                joystick.Properties.BufferSize = 128;

                // Acquire the joystick
                joystick.Acquire();

                tHopScotch.Start();
            }
        }