当前位置: 首页>>代码示例>>C#>>正文


C# Joystick.SetCooperativeLevel方法代码示例

本文整理汇总了C#中Joystick.SetCooperativeLevel方法的典型用法代码示例。如果您正苦于以下问题:C# Joystick.SetCooperativeLevel方法的具体用法?C# Joystick.SetCooperativeLevel怎么用?C# Joystick.SetCooperativeLevel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Joystick的用法示例。


在下文中一共展示了Joystick.SetCooperativeLevel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Initialize

		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);
			}
		}
开发者ID:henke37,项目名称:BizHawk,代码行数:27,代码来源:GamePad.cs

示例2: NesVSUnisystemDIPJoystickConnection

        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;
        }
开发者ID:ywjno,项目名称:mynes-code,代码行数:30,代码来源:NesVSUnisystemDIPJoystickConnection.cs

示例3: GetJoystick

        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;
        }
开发者ID:Cyborg11,项目名称:FreePIE,代码行数:33,代码来源:PPJoyPluginTest.cs

示例4: Reconnect

        public override void Reconnect()
        {
            // search for devices
            foreach (DeviceInstance device in _DInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                // create the device
                try
                {
                    _Joy = new Joystick(_DInput, device.InstanceGuid);
                    _Joy.SetCooperativeLevel(wnd_int, CooperativeLevel.Nonexclusive | CooperativeLevel.Background);
                    break;
                }
                catch (DirectInputException)
                {
                }
            }
            if (_Joy == null)
            {
                IsConnected = false;
                Name = "";
                Type = "";
                return;
            }

            _Joy.Acquire();

            IsConnected = true;
            Name = _Joy.Information.ProductName;
            Type = "DirectInput";
        }
开发者ID:uamt-brno,项目名称:RaspBot,代码行数:30,代码来源:JoyDirectInput.cs

示例5: MainController

        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();
        }
开发者ID:martikaljuve,项目名称:Robin,代码行数:27,代码来源:MainController.cs

示例6: NesJoypadPcJoystickConnection

        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);
        }
开发者ID:Blizz9,项目名称:FanCut,代码行数:27,代码来源:NesJoypadPcJoystickConnection.cs

示例7: DirectInputManager

        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.");
        }
开发者ID:pushtechnology,项目名称:blog-steering-wheel,代码行数:34,代码来源:DirectInputManager.cs

示例8: Acquire

        public void Acquire(Form parent)
        {
            var dinput = new DirectInput();

            Pad = new Joystick(dinput, Guid);
            foreach (DeviceObjectInstance doi in Pad.GetObjects(ObjectDeviceType.Axis))
            {
                Pad.GetObjectPropertiesById((int) doi.ObjectType).SetRange(-5000, 5000);
            }

            Pad.Properties.AxisMode = DeviceAxisMode.Absolute;
            Pad.SetCooperativeLevel(parent, (CooperativeLevel.Nonexclusive | CooperativeLevel.Background));
            ButtonCount = Pad.Capabilities.ButtonCount;
            Pad.Acquire();
        }
开发者ID:tobig82,项目名称:iRduino,代码行数:15,代码来源:ControllerDevice.cs

示例9: Initialize

        public override void Initialize()
        {
            buttonDown = -1;
            joystickIsReady = false;

            // Make sure that DirectInput has been initialized
            DirectInput dinput = new DirectInput();
            state = new JoystickState();

            // search for devices
            foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                // create the device
                try
                {
                    joystick = new Joystick(dinput, device.InstanceGuid);
                    joystick.SetCooperativeLevel(Core.Settings.RenderForm.Handle,
                        CooperativeLevel.Exclusive | CooperativeLevel.Foreground);
                    break;
                }
                catch (DirectInputException)
                {
                }
            }

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

            // acquire the device
            joystick.Acquire();

            timer = new Timer();
            timer.Interval = 1000 / 10;
            timer.Tick += new EventHandler(timer_Tick);
            timer.Start();
        }
开发者ID:zulis,项目名称:Cubica,代码行数:46,代码来源:JoyStick.cs

示例10: CreateGlobal

        public override object CreateGlobal()
        {
            var directInput = new DirectInput();
            var handle = Process.GetCurrentProcess().MainWindowHandle;
            devices = new List<Device>();

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

                devices.Add(new Device(controller));
            }

            return devices.Select(d => new JoystickGlobal(d)).ToArray();
        }
开发者ID:tagaf,项目名称:FreePIE,代码行数:17,代码来源:JoystickPlugin.cs

示例11: CreateDevice

        void CreateDevice()
        {
            // 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
                {
                    joystick = new Joystick(dinput, device.InstanceGuid);
                    joystick.SetCooperativeLevel(this, CooperativeLevel.Exclusive | CooperativeLevel.Foreground);
                    break;
                }
                catch (DirectInputException)
                {
                }
            }

            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(0, 255);
                }

                UpdateControl(deviceObject);
            }

            // acquire the device
            joystick.Acquire();

            // set the timer to go off 12 times a second to read input
            // NOTE: Normally applications would read this much faster.
            // This rate is for demonstration purposes only.
            timer.Interval = 5; // 1000 / 1000;
            timer.Start();
        }
开发者ID:volkansalma,项目名称:usbHid1769,代码行数:46,代码来源:MainForm.cs

示例12: Input

        public Input(Game game, IntPtr handle)
            : base(game, -10000)
        {
            _directInput = new DirectInput();
            _keyboard = new Keyboard(_directInput);
            _keyboard.Properties.BufferSize = 256;
            _keyboard.SetCooperativeLevel(handle, CooperativeLevel.Background | CooperativeLevel.NonExclusive);
            _mouse = new Mouse(_directInput);
            _mouse.Properties.AxisMode = DeviceAxisMode.Relative;
            _mouse.SetCooperativeLevel(handle, CooperativeLevel.Background | CooperativeLevel.NonExclusive);

            var devices  = _directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices);
            if (devices.Count > 0)
            {
                _joystick = new Joystick(_directInput, devices[0].InstanceGuid);
                _joystick.SetCooperativeLevel(handle, CooperativeLevel.Background | CooperativeLevel.NonExclusive);
            }
        }
开发者ID:ndech,项目名称:PlaneSimulator,代码行数:18,代码来源:Input.cs

示例13: FormKey

        public FormKey(SlimDX.DirectInput.DeviceType type, string deviceGuid, string keyName)
        {
            this.deviceType = type;
            InitializeComponent();

            DirectInput di = new DirectInput();

            switch (type)
            {
                case SlimDX.DirectInput.DeviceType.Keyboard:
                    {
                        keyboard = new Keyboard(di);
                        keyboard.SetCooperativeLevel(this.Handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground);
                        break;
                    }
                case SlimDX.DirectInput.DeviceType.Joystick:
                    {
                        joystick = new Joystick(di, Guid.Parse(deviceGuid));
                        joystick.SetCooperativeLevel(this.Handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground);

                        break;
                    }
                case SlimDX.DirectInput.DeviceType.Other:
                    {
                        switch (deviceGuid)
                        {
                            case "x-controller-1": x_controller = new Controller(UserIndex.One); break;
                            case "x-controller-2": x_controller = new Controller(UserIndex.Two); break;
                            case "x-controller-3": x_controller = new Controller(UserIndex.Three); break;
                            case "x-controller-4": x_controller = new Controller(UserIndex.Four); break;
                        }
                        break;
                    }
            }

            timer_hold.Start();
            label1.Text = string.Format(Program.ResourceManager.GetString("Text_PressAKeyFor") + " [{0}]", keyName);
            stopTimer = 10;
            label_cancel.Text = string.Format(Program.ResourceManager.GetString("Status_CancelIn") + " {0} " +
                Program.ResourceManager.GetString("Status_Seconds"), stopTimer);
            timer2.Start();
            this.Select();
        }
开发者ID:ywjno,项目名称:mynes-code,代码行数:43,代码来源:FormKey.cs

示例14: InputManager

 public InputManager(IntPtr handle)
 {
     _devices = new List<InputDevice>();
     var di = new DirectInput();
     foreach (var device in di.GetDevices(DeviceClass.All, DeviceEnumerationFlags.AttachedOnly))
     {
         if ((device.Type & DeviceType.Keyboard) == DeviceType.Keyboard)
         {
             var keyboard = new Keyboard(di);
             keyboard.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground);
             _devices.Add(new InputDevice(keyboard));
         }
         else if ((device.Type & DeviceType.Joystick) == DeviceType.Joystick)
         {
             var joystick = new Joystick(di, device.InstanceGuid);
             joystick.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground);
             _devices.Add(new InputDevice(joystick));
         }
     }
 }
开发者ID:afonsof,项目名称:nes-hd,代码行数:20,代码来源:InputManager.cs

示例15: InitializeDevices

        private void InitializeDevices()
        {
            var handle = WrenCore.WindowHandle;

            _joysticks = new List<Joystick>();

            DirectInput di = new DirectInput();

            foreach (var device in di.GetDevices(DeviceClass.All, DeviceEnumerationFlags.AttachedOnly))
            {
                if ((device.Type & DeviceType.Keyboard) == DeviceType.Keyboard)
                {
                    Keyboard keyboard = new Keyboard(di);
                    keyboard.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground);
                    _keyboard = keyboard;
                }
                else if ((device.Type & DeviceType.Joystick) == DeviceType.Joystick)
                {
                    Joystick joystick = new Joystick(di, device.InstanceGuid);
                    joystick.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground);
                    _joysticks.Add(joystick);
                }
            }
        }
开发者ID:PhilipBrockmeyer,项目名称:Wren,代码行数:24,代码来源:InputManager.cs


注:本文中的Joystick.SetCooperativeLevel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。