本文整理汇总了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();
}
}
示例2: GamePad
public GamePad(DirectInput directInput, DeviceInstance deviceInstance)
{
this.directInput = directInput;
this.device = new Joystick(directInput, deviceInstance.InstanceGuid);
this.device.Acquire();
UpdateState();
}
示例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();
}
示例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();
}
}
示例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();
}
示例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();
}
示例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.");
}
示例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);
}
示例9: ResolveDependencies
protected override void ResolveDependencies()
{
base.ResolveDependencies();
this.leftJoystick = this.EntityManager.Find<Joystick>("leftJoystick");
this.fireButton = this.EntityManager.Find<FireButton>("fireButton");
}
示例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;
}
示例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();
}
示例12: GhiJoystickInputProvider
public GhiJoystickInputProvider(Joystick joystick)
{
if (joystick == null) throw new ArgumentNullException("joystick");
_joystick = joystick;
_joystick.JoystickPressed += joystick_JoystickPressed;
_joystick.JoystickReleased += joystick_JoystickReleased;
}
示例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
}
示例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();
}
示例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);
}