本文整理汇总了C#中Joystick.GetObjects方法的典型用法代码示例。如果您正苦于以下问题:C# Joystick.GetObjects方法的具体用法?C# Joystick.GetObjects怎么用?C# Joystick.GetObjects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Joystick
的用法示例。
在下文中一共展示了Joystick.GetObjects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: 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);
}
}
示例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;
}
示例4: 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 ();
}
示例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();
}
示例6: 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();
}
示例7: 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();
}
示例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();
}
示例9: InputDeviceImp
/// <summary>
/// Initializes a new instance of the <see cref="InputDeviceImp"/> class.
/// </summary>
/// <param name="instance">The DeviceInstance.</param>
public InputDeviceImp(DeviceInstance instance)
{
_controller = instance;
_deadZone = 0.1f;
buttonsPressed = new bool[100];
_joystick = new Joystick(new DirectInput(), _controller.InstanceGuid);
foreach (DeviceObjectInstance deviceObject in _joystick.GetObjects())
{
if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
_joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000);
}
_joystick.Acquire();
}
示例10: 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(-1000, 1000);
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 = 1000 / 12;
timer.Start();
}
示例11: GetSticks
// --- INITIALIZTION ---
public int GetSticks(IMatchDisplay form)
{
_form = form;
DirectInput Input = new DirectInput();
List<Joystick> sticks = new List<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
{
var stick = new 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)
{
}
}
Sticks = sticks.ToArray();
var count = Sticks.Length;
if (count > 0)
{
tm1939LoadSticks();
}
return count; // sticks.ToArray();
}
示例12: CreateDevice
private void CreateDevice(int idGamepad)
{
// make sure that DirectInput has been initialized
DirectInput dinput = new DirectInput();
foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
{
try
{
joystick = new Joystick(dinput, device.InstanceGuid);
//joystick.SetCooperativeLevel(windowHandle, CooperativeLevel.Exclusive | CooperativeLevel.Foreground);
if (joystick.Properties.JoystickId == idGamepad)
break;
}
catch (DirectInputException)
{
}
}
if (joystick == null)
{
//throw new Exception("There are no joysticks attached to the system.");
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(-1000, 1000);
//UpdateControl(deviceObject);
}
joystick.Acquire();
}
示例13: 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();
}
示例14: ShowDeviceInfo
void ShowDeviceInfo(Joystick device)
{
if (device == null)
{
// clean everything here.
SetValue(DeviceProductNameTextBox, "");
SetValue(DeviceProductGuidTextBox, "");
SetValue(DeviceInstanceGuidTextBox, "");
DiCapFfStateTextBox.Text = string.Empty;
DiCapAxesTextBox.Text = string.Empty;
DiCapButtonsTextBox.Text = string.Empty;
DiCapDPadsTextBox.Text = string.Empty;
DiEffectsTable.Rows.Clear();
return;
}
lock (MainForm.XInputLock)
{
var isLoaded = XInput.IsLoaded;
if (isLoaded) XInput.FreeLibrary();
device.Unacquire();
device.SetCooperativeLevel(MainForm.Current, CooperativeLevel.Foreground | CooperativeLevel.Exclusive);
effects = new List<EffectInfo>();
try
{
device.Acquire();
var forceFeedback = device.Capabilities.Flags.HasFlag(DeviceFlags.ForceFeedback);
forceFeedbackState = forceFeedback ? "YES" : "NO";
effects = device.GetEffects(EffectType.All);
}
catch (Exception)
{
forceFeedbackState = "ERROR";
}
DiEffectsTable.Rows.Clear();
foreach (var eff in effects)
{
DiEffectsTable.Rows.Add(new object[]{
eff.Name,
((EffectParameterFlags)eff.StaticParameters).ToString(),
((EffectParameterFlags)eff.DynamicParameters).ToString()
});
}
device.Unacquire();
device.SetCooperativeLevel(MainForm.Current, CooperativeLevel.Background | CooperativeLevel.NonExclusive);
if (isLoaded)
{
Exception error;
XInput.ReLoadLibrary(XInput.LibraryName, out error);
}
}
DiCapFfStateTextBox.Text = forceFeedbackState;
DiCapButtonsTextBox.Text = device.Capabilities.ButtonCount.ToString();
DiCapDPadsTextBox.Text = device.Capabilities.PovCount.ToString();
var objects = device.GetObjects(DeviceObjectTypeFlags.All).OrderBy(x => x.Offset).ToArray();
DiObjectsTable.Rows.Clear();
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();
foreach (var o in objects)
{
DiObjectsTable.Rows.Add(new object[]{
o.Offset,
o.ObjectId.InstanceNumber,
o.Usage,
o.Name,
o.Aspect,
guids.Contains(o.ObjectType) ? names[guids.IndexOf(o.ObjectType)] : o.ObjectType.ToString(),
o.ObjectId.Flags,
});
}
var actuators = objects.Where(x => x.ObjectId.Flags.HasFlag(DeviceObjectTypeFlags.ForceFeedbackActuator));
ActuatorsTextBox.Text = actuators.Count().ToString();
var di = device.Information;
var slidersCount = objects.Where(x => x.ObjectType.Equals(SharpDX.DirectInput.ObjectGuid.Slider)).Count();
DiCapAxesTextBox.Text = (device.Capabilities.AxeCount - slidersCount).ToString();
SlidersTextBox.Text = slidersCount.ToString();
// Update PID and VID always so they wont be overwritten by load settings.
short vid = BitConverter.ToInt16(di.ProductGuid.ToByteArray(), 0);
short pid = BitConverter.ToInt16(di.ProductGuid.ToByteArray(), 2);
SetValue(DeviceVidTextBox, "0x{0}", vid.ToString("X4"));
SetValue(DevicePidTextBox, "0x{0}", pid.ToString("X4"));
SetValue(DeviceProductNameTextBox, di.ProductName);
SetValue(DeviceProductGuidTextBox, di.ProductGuid.ToString());
SetValue(DeviceInstanceGuidTextBox, di.InstanceGuid.ToString());
SetValue(DeviceTypeTextBox, di.Type.ToString());
}
示例15: 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)
{
LogMessage("There are no joysticks attached to the system.");
LogMessage("Restart application after connecting stick.");
return;
}
foreach (DeviceObjectInstance deviceObject in joystick.GetObjects())
{
if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000);
}
// acquire the device
joystick.Acquire();
}