• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Joystick类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: CaptureJoysticks

        public void CaptureJoysticks()
        {
            // Initialize DirectInput
            var directInput = new DirectInput();

            // Find all joysticks connected to the system
            IList<DeviceInstance> connectedJoysticks = new List<DeviceInstance>();
            // - look for gamepads
            foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices))
            {
                connectedJoysticks.Add(deviceInstance);
            }
            // - look for joysticks
            foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices))
            {
                connectedJoysticks.Add(deviceInstance);
            }

            // Use the two first joysticks found
            if (connectedJoysticks.Count >= 1)
            {
                joystick1 = new Joystick(directInput, connectedJoysticks[0].InstanceGuid);
                Joystick1DeviceName = connectedJoysticks[0].InstanceName;
                joystick1.Acquire();
            }
            if (connectedJoysticks.Count >= 2)
            {
                joystick2 = new Joystick(directInput, connectedJoysticks[1].InstanceGuid);
                Joystick2DeviceName = connectedJoysticks[1].InstanceName;
                joystick2.Acquire();
            }
        }
开发者ID:laurentprudhon,项目名称:ZxSpectrumSimulator,代码行数:32,代码来源:JoystickAdapter.cs


示例2: GamePad

 public GamePad(DirectInput directInput, DeviceInstance deviceInstance)
 {
     this.directInput = directInput;
     this.device = new Joystick(directInput, deviceInstance.InstanceGuid);
     this.device.Acquire();
     UpdateState();
 }
开发者ID:Hendrik410,项目名称:KKS_Drone,代码行数:7,代码来源:GamePad.cs


示例3: DirectInputGamePad

 public DirectInputGamePad(DirectInput directInput, GamePadKey key) : base(key)
 {
     this.key = key;
     this.directInput = directInput;
     this.instance = new Joystick(directInput, key.Guid);
     joystickState = new JoystickState();
 }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:7,代码来源:InputManager.Windows.DirectInput.cs


示例4: Lock_DX_Devices

        //Disable all dinput devices for xinput controllers
        public void Lock_DX_Devices()
        {
            var directInput = new DirectInput();

            try
            {
                IList<DeviceInstance> devicelist = directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AttachedOnly);

                foreach (DeviceInstance cdevice in devicelist)
                {
                    if (cdevice.InstanceName.Trim('\0') == XINPUT_NAME)
                    {
                        var joystick = new Joystick(directInput, cdevice.InstanceGuid);
                        joystick.Acquire();
                        Guid deviceGUID = joystick.Properties.ClassGuid;
                        string devicePath = joystick.Properties.InterfacePath;
                        joystick.Unacquire();
                        string[] dpstlit = devicePath.Split('#');
                        devicePath = @"HID\" + dpstlit[1].ToUpper() + @"\" + dpstlit[2].ToUpper();
                        lockedDevices.Add(new DeviceID(deviceGUID, devicePath));

                        DeviceHelper.SetDeviceEnabled(deviceGUID, devicePath, false);
                    }
                }
            }
            finally
            {
                directInput.Dispose();
            }
        }
开发者ID:TheLastRar,项目名称:SCP2vJoy,代码行数:31,代码来源:DXinputLocker.cs


示例5: ConfigEditDialog_Load

		private void ConfigEditDialog_Load(object sender, EventArgs e)
		{
			directInput = new DirectInput();
            var list = directInput.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly);
            if (list.Count > 0)
            {
                inputDevice = new Joystick(directInput, list.First().InstanceGuid);
                tableLayoutPanel1.RowCount = actionNames.Length;
                for (int i = 0; i < actionNames.Length; i++)
                {
                    tableLayoutPanel1.Controls.Add(new Label() 
                    {
                        AutoSize = true,
                        Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Top,
                        Text = actionNames[i],
                        TextAlign = ContentAlignment.MiddleLeft
                    }, 0, i);
                    ButtonControl buttonControl = new ButtonControl() { Enabled = false };
                    tableLayoutPanel1.Controls.Add(buttonControl, 1, i);
                    buttonControls.Add(buttonControl);
                    buttonControl.SetButtonClicked += buttonControl_SetButtonClicked;
                    buttonControl.ClearButtonClicked += buttonControl_ClearButtonClicked;
                    if (i == tableLayoutPanel1.RowStyles.Count)
                        tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize));
                }
            }
            else
                tabControl1.TabPages.Remove(tabPage_Controller);
            // Load the config INI upon window load
			LoadConfigIni();
		}
开发者ID:DankRank,项目名称:sadx-mod-loader,代码行数:31,代码来源:ConfigEditDialog.cs


示例6: GamePadDevice

        /// <summary>
        /// 番号指定でデバイス生成。番号のデバイスが存在しなければ例外を投げる。
        /// </summary>
        /// <param name="window"></param>
        /// <param name="padNumber">0始まり</param>
        public GamePadDevice(int padNumber, DirectInput directInput)
        {
            var devices = GetDevices(directInput);
            if (devices.Count <= padNumber)
            {
                throw new Exception("指定された数のパッドがつながれていない");
            }
            try
            {
                Stick = new Joystick(directInput, devices[padNumber].InstanceGuid);
                //Stick.SetCooperativeLevel(window, CooperativeLevel.Exclusive | CooperativeLevel.Foreground);
            }
            catch (Exception e)
            {
                throw new Exception("パッドの初期化に失敗", e);
            }

            ///スティックの範囲設定
            foreach (var item in Stick.GetObjects())
            {
                //if ((item.ObjectType & .Axis) != 0)
                //{
                //	Stick.GetObjectPropertiesById((int)item.ObjectType).SetRange(-1000, 1000);
                //}

            }
            Stick.Acquire();
        }
开发者ID:MasakiMuto,项目名称:MasaLibs,代码行数:33,代码来源:GamePadDevice.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: 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


示例9: ResolveDependencies

        protected override void ResolveDependencies()
        {
            base.ResolveDependencies();

            this.leftJoystick = this.EntityManager.Find<Joystick>("leftJoystick");
            this.fireButton = this.EntityManager.Find<FireButton>("fireButton");
        }
开发者ID:dezol,项目名称:QuickStarters,代码行数:7,代码来源:PlayerBehavior.cs


示例10: SetJoystickByName

        public bool SetJoystickByName(string name)
        {
            WriteLog("Searching joystick!");

            // Find joystick
            foreach (DeviceInstance deviceInstance in GetJoysticks()) {
                if (deviceInstance.InstanceName.StartsWith(name, StringComparison.CurrentCulture)) {
                    joystickGuid = deviceInstance.InstanceGuid;
                }
            }

            // Joystick not found!
            if (joystickGuid == Guid.Empty) {
                WriteLog("Joystick not found!");
                return false;
            }
            WriteLog("Joystick found!");

            // Create & acquire the joystick
            joystick = new Joystick(directInput, joystickGuid);
            joystick.Properties.BufferSize = 128;
            joystick.Acquire();

            WriteLog("Joystick '" + joystick.Properties.InstanceName + "' found!");

            return true;
        }
开发者ID:hawku,项目名称:G25Adapter,代码行数:27,代码来源:JoystickManager.cs


示例11: GetDeviceObjects

 public static DeviceObjectItem[] GetDeviceObjects(Joystick device)
 {
     var og = typeof(SharpDX.DirectInput.ObjectGuid);
     var guidFileds = og.GetFields().Where(x => x.FieldType == typeof(Guid));
     List<Guid> guids = guidFileds.Select(x => (Guid)x.GetValue(og)).ToList();
     List<string> names = guidFileds.Select(x => x.Name).ToList();
     var objects = device.GetObjects(DeviceObjectTypeFlags.All).OrderBy(x => x.Offset).ToArray();
     var items = new List<DeviceObjectItem>();
     foreach (var o in objects)
     {
         var item = new DeviceObjectItem()
         {
             Name = o.Name,
             Offset = o.Offset,
             Instance = o.ObjectId.InstanceNumber,
             Usage = o.Usage,
             Aspect = o.Aspect,
             Flags = o.ObjectId.Flags,
             GuidValue = o.ObjectType,
             GuidName = guids.Contains(o.ObjectType) ? names[guids.IndexOf(o.ObjectType)] : o.ObjectType.ToString(),
         };
         items.Add(item);
     }
     return items.ToArray();
 }
开发者ID:Grommini,项目名称:x360ce,代码行数:25,代码来源:AppHelper.cs


示例12: GhiJoystickInputProvider

 public GhiJoystickInputProvider(Joystick joystick)
 {
     if (joystick == null) throw new ArgumentNullException("joystick");
       _joystick = joystick;
       _joystick.JoystickPressed += joystick_JoystickPressed;
       _joystick.JoystickReleased += joystick_JoystickReleased;
 }
开发者ID:ianlee74,项目名称:Gadgetab,代码行数:7,代码来源:GhiJoystickInputProvider.cs


示例13: InitJoystick

    protected void InitJoystick()
    {
        #if UNITY_IPHONE || UNITY_ANDROID || UNITY_WP8 || UNITY_BLACKBERRY
        if (joystickPrefab) {
            // Create left joystick
            GameObject joystickLeftGO = Instantiate (joystickPrefab) as GameObject;
            joystickLeftGO.name = "Joystick Left";
            joystickLeft = joystickLeftGO.GetComponent<Joystick> ();

            GUITexture guiTex = joystickLeftGO.GetComponent<GUITexture> ();
            joystickLeftRect = new Rect(0, 0,//Screen.height - guiTex.pixelInset.y - guiTex.pixelInset.height,
                guiTex.pixelInset.x + guiTex.pixelInset.width, guiTex.pixelInset.y + guiTex.pixelInset.height);

            // Create right joystick
            joystickRightGO = Instantiate (joystickPrefab) as GameObject;
            joystickRightGO.name = "Joystick Right";
            joystickRight = joystickRightGO.GetComponent<Joystick> ();
            joystickRight.touchPad = true;
            GUITexture guiTexRight = joystickRightGO.GetComponent<GUITexture> ();

            string texture = "Common/Joystick/ShootButton";//"Textures/ThumbStickPad";
            Texture2D inputTexture = Resources.Load(texture, typeof(Texture2D)) as Texture2D;
            guiTexRight.texture = inputTexture;
        }
        #endif
    }
开发者ID:u3breeze,项目名称:Unity3d-GrapplingHook,代码行数:26,代码来源:JoystickController.cs


示例14: 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


示例15: UpdateFrom

 public void UpdateFrom(Joystick device, out JoystickState state)
 {
     if (!AppHelper.IsSameDevice(device, deviceInstanceGuid))
     {
         ShowDeviceInfo(device);
         deviceInstanceGuid = Guid.Empty;
         if (device != null)
         {
             deviceInstanceGuid = device.Information.InstanceGuid;
             isWheel = device.Information.Type == SharpDX.DirectInput.DeviceType.Driving;
         }
     }
     state = null;
     if (device != null)
     {
         try
         {
             device.Acquire();
             state = device.GetCurrentState();
         }
         catch (Exception ex)
         {
             var error = ex;
         }
     }
     ShowDirectInputState(state);
 }
开发者ID:suvjunmd,项目名称:x360ce,代码行数:27,代码来源:DirectInputControl.cs


示例16: GamepadReader

        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 ();
        }
开发者ID:Karl-Parris,项目名称:NintendoSpy,代码行数:28,代码来源:GamepadReader.cs


示例17: startObjective

    public override IEnumerator startObjective()
    {
        player = GameObject.FindWithTag("Player").GetComponent<Player>();
        //Moves the player closer to the gap
        joyStickScript = joystick.GetComponent<Joystick>();
        while (player.transform.position.x < 18)
        {
            joyStickScript.UpdateVirtualAxes(new Vector3(joyStickScript.m_StartPos.x + 20, joyStickScript.m_StartPos.y));
            yield return new WaitForSeconds((float)0.01);
        }
        joyStickScript.OnPointerUp(null);

        Text stageText = stageTextObject.GetComponent<Text>();
        stageText.text = "Drop down the gap to respawn above";
        //Enables the buttons
        joystick.GetComponent<Image>().enabled = true;
        while (!isCompleted())
        {
            yield return new WaitForSeconds((float)0.1);
        }
        //Disables the buttons
        joystick.GetComponent<Image>().enabled = false;
        stageText.text = "Remember! Enemies get a speed boost when they drop into a gap";
        yield return new WaitForSeconds(3);
    }
开发者ID:unit02,项目名称:SoftEng-306-Project-2,代码行数:25,代码来源:Looper.cs


示例18: 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


示例19: SimpleJoystick

        /// 
        /// 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();
        }
开发者ID:wariw,项目名称:360Joypad_test,代码行数:33,代码来源:SimpleJoystick.cs


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# JoystickState类代码示例发布时间:2022-05-24
下一篇:
C# JointType类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap