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


C# Joystick类代码示例

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


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


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