本文整理汇总了C#中Joystick.GetObjectPropertiesById方法的典型用法代码示例。如果您正苦于以下问题:C# Joystick.GetObjectPropertiesById方法的具体用法?C# Joystick.GetObjectPropertiesById怎么用?C# Joystick.GetObjectPropertiesById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Joystick
的用法示例。
在下文中一共展示了Joystick.GetObjectPropertiesById方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: 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();
}
示例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: 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);
}
}
示例6: 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();
}
示例7: 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();
}
示例8: 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();
}
示例9: 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();
}
示例10: InitializeGamepad
private void InitializeGamepad()
{
// 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 SlimDX.DirectInput.Joystick(dinput, device.InstanceGuid);
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();
}
示例11: btnAcquireJs_Click
private void btnAcquireJs_Click(object sender, EventArgs e)
{
// Search for device
foreach (DeviceInstance device in dInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
{
try
{
jStick = new Joystick(dInput, device.InstanceGuid);
break;
}
catch (DirectInputException){}
}
if (jStick == null)
MessageBox.Show("Failed to acquire joystick.", "Joystick Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
else
{
foreach (DeviceObjectInstance deviceObject in jStick.GetObjects())
{
if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
jStick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(jsRangeLower, jsRangeUpper);
}
jStick.Acquire();
btnStartStop.Enabled = true;
}
}
示例12: createSliderReader
/// <summary>Creates a slider reader for the specified object</summary>
/// <param name="joystick">Joystick providing the control object</param>
/// <param name="slider">Slider a reader will be created for</param>
/// <param name="control">Control description for the axis</param>
/// <returns>A new slider reader for the specified axis</returns>
private static ISliderReader createSliderReader(
Joystick joystick, Sliders slider, DeviceObjectInstance control
)
{
int id = (int) control.ObjectType;
ObjectProperties properties = joystick.GetObjectPropertiesById(id);
int min = properties.LowerRange;
int max = properties.UpperRange;
switch (slider)
{
case Sliders.Slider1:
{
return new SliderReader(0, min, max);
}
case Sliders.Slider2:
{
return new SliderReader(1, min, max);
}
case Sliders.Velocity1:
{
return new VelocitySliderReader(0, min, max);
}
case Sliders.Velocity2:
{
return new VelocitySliderReader(1, min, max);
}
case Sliders.Acceleration1:
{
return new AccelerationSliderReader(0, min, max);
}
case Sliders.Acceleration2:
{
return new AccelerationSliderReader(1, min, max);
}
case Sliders.Force1:
{
return new ForceSliderReader(0, min, max);
}
case Sliders.Force2:
{
return new ForceSliderReader(1, min, max);
}
default:
{
return null;
}
}
}
示例13: createAxisReader
/// <summary>Creates an axis reader for the specified object</summary>
/// <param name="joystick">Joystick providing the control object</param>
/// <param name="axis">Axis a reader will be created for</param>
/// <param name="control">Control description for the axis</param>
/// <returns>A new axis reader for the specified axis</returns>
private static IAxisReader createAxisReader(
Joystick joystick, Axes axis, DeviceObjectInstance control
)
{
int id = (int) control.ObjectType;
ObjectProperties properties = joystick.GetObjectPropertiesById(id);
int min = properties.LowerRange;
int max = properties.UpperRange;
switch (axis)
{
case Axes.X:
{
return new XAxisReader(min, max);
}
case Axes.Y:
{
return new YAxisReader(min, max);
}
case Axes.Z:
{
return new ZAxisReader(min, max);
}
case Axes.VelocityX:
{
return new VelocityXAxisReader(min, max);
}
case Axes.VelocityY:
{
return new VelocityYAxisReader(min, max);
}
case Axes.VelocityZ:
{
return new VelocityZAxisReader(min, max);
}
case Axes.AccelerationX:
{
return new AccelerationXAxisReader(min, max);
}
case Axes.AccelerationY:
{
return new AccelerationYAxisReader(min, max);
}
case Axes.AccelerationZ:
{
return new AccelerationZAxisReader(min, max);
}
case Axes.ForceX:
{
return new ForceXAxisReader(min, max);
}
case Axes.ForceY:
{
return new ForceYAxisReader(min, max);
}
case Axes.ForceZ:
{
return new ForceZAxisReader(min, max);
}
case Axes.RotationX:
{
return new RotationXAxisReader(min, max);
}
case Axes.RotationY:
{
return new RotationYAxisReader(min, max);
}
case Axes.RotationZ:
{
return new RotationZAxisReader(min, max);
}
case Axes.AngularVelocityX:
{
return new AngularVelocityXAxisReader(min, max);
}
case Axes.AngularVelocityY:
{
return new AngularVelocityYAxisReader(min, max);
}
case Axes.AngularVelocityZ:
{
return new AngularVelocityZAxisReader(min, max);
}
case Axes.AngularAccelerationX:
{
return new AngularAccelerationXAxisReader(min, max);
}
case Axes.AngularAccelerationY:
{
return new AngularAccelerationYAxisReader(min, max);
}
case Axes.AngularAccelerationZ:
{
return new AngularAccelerationZAxisReader(min, max);
//.........这里部分代码省略.........
示例14: 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();
}
示例15: 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();
}