本文整理汇总了C#中Joystick.Unacquire方法的典型用法代码示例。如果您正苦于以下问题:C# Joystick.Unacquire方法的具体用法?C# Joystick.Unacquire怎么用?C# Joystick.Unacquire使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Joystick
的用法示例。
在下文中一共展示了Joystick.Unacquire方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
}
示例2: getFirstPressedButton
public void getFirstPressedButton()
{
while (listening)
{
foreach (var deviceInstance in directInput.GetDevices(DeviceType.Driving,
DeviceEnumerationFlags.AllDevices))
{
Guid joystickGuid = deviceInstance.InstanceGuid;
if (joystickGuid == Guid.Empty)
{
listening = false;
}
else
{
// Instantiate the joystick
var joystick = new Joystick(directInput, joystickGuid);
Console.WriteLine("Found Joystick/Gamepad with GUID: {0}", joystickGuid);
// Acquire the joystick
joystick.Acquire();
JoystickState state = joystick.GetCurrentState();
Boolean[] buttons = state.Buttons;
Boolean useThisJoystick = false;
for (int i = 0; i < buttons.Count(); i++)
{
if (buttons[i])
{
this.joystickToUse = joystick;
this.buttonIndex = i;
Console.WriteLine("Using button index " + buttonIndex + " for device guid " + joystickGuid);
listening = false;
useThisJoystick = true;
break;
}
}
if (!useThisJoystick)
{
joystick.Unacquire();
}
}
}
Thread.Sleep(1000);
}
Console.WriteLine("Got button " + buttonIndex);
}
示例3: 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());
}
示例4: ShowDeviceInfo
void ShowDeviceInfo(Joystick device, DeviceInfo dInfo)
{
if (device == null)
{
// clean everything here.
AppHelper.SetText(DeviceProductNameTextBox, "");
AppHelper.SetText(DeviceVendorNameTextBox, "");
AppHelper.SetText(DeviceProductGuidTextBox, "");
AppHelper.SetText(DeviceInstanceGuidTextBox, "");
AppHelper.SetText(DiCapFfStateTextBox, "");
AppHelper.SetText(DiCapAxesTextBox, "");
AppHelper.SetText(DiCapButtonsTextBox, "");
AppHelper.SetText(DiCapDPadsTextBox, "");
if (DiEffectsTable.Rows.Count > 0) 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);
}
}
AppHelper.SetText(DiCapFfStateTextBox, forceFeedbackState);
AppHelper.SetText(DiCapButtonsTextBox, device.Capabilities.ButtonCount.ToString());
AppHelper.SetText(DiCapDPadsTextBox, device.Capabilities.PovCount.ToString());
var objects = AppHelper.GetDeviceObjects(device);
DiObjectsDataGridView.DataSource = objects;
var actuators = objects.Where(x => x.Flags.HasFlag(DeviceObjectTypeFlags.ForceFeedbackActuator));
AppHelper.SetText(ActuatorsTextBox, actuators.Count().ToString());
var di = device.Information;
var slidersCount = objects.Where(x => x.GuidValue.Equals(SharpDX.DirectInput.ObjectGuid.Slider)).Count();
AppHelper.SetText(DiCapAxesTextBox, (device.Capabilities.AxeCount - slidersCount).ToString());
AppHelper.SetText(SlidersTextBox, 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);
AppHelper.SetText(DeviceVidTextBox, "0x{0:X4}", vid);
AppHelper.SetText(DevicePidTextBox, "0x{0:X4}", pid);
AppHelper.SetText(DeviceProductNameTextBox, di.ProductName);
AppHelper.SetText(DeviceVendorNameTextBox, dInfo == null ? "" : dInfo.Manufacturer);
AppHelper.SetText(DeviceRevTextBox, "0x{0:X4}", dInfo == null ? 0 : dInfo.Revision);
AppHelper.SetText(DeviceProductGuidTextBox, di.ProductGuid.ToString());
AppHelper.SetText(DeviceInstanceGuidTextBox, di.InstanceGuid.ToString());
AppHelper.SetText(DeviceTypeTextBox, di.Type.ToString());
}
示例5: ReleaseDevice
void ReleaseDevice(Joystick j)
{
timerJoystickRead.Stop();
if (j != null)
{
try
{
j.Unacquire();
j.Dispose();
}
catch { }
}
j = null;
}
示例6: getFirstPressedButton
private Boolean getFirstPressedButton(System.Windows.Forms.Form parent, ControllerData controllerData, ButtonAssignment buttonAssignment)
{
listenForAssignment = true;
// Instantiate the joystick
var joystick = new Joystick(directInput, controllerData.guid);
// Acquire the joystick
joystick.SetCooperativeLevel(parent, (CooperativeLevel.NonExclusive | CooperativeLevel.Background));
joystick.Properties.BufferSize = 128;
joystick.Acquire();
Boolean gotAssignment = false;
while (listenForAssignment)
{
Boolean[] buttons = joystick.GetCurrentState().Buttons;
for (int i = 0; i < buttons.Count(); i++)
{
if (buttons[i])
{
Console.WriteLine("Got button at index " + i);
removeAssignmentsForControllerAndButton(controllerData.guid, i);
buttonAssignment.controller = controllerData;
buttonAssignment.joystick = joystick;
buttonAssignment.buttonIndex = i;
listenForAssignment = false;
gotAssignment = true;
}
}
}
if (!gotAssignment)
{
joystick.Unacquire();
}
return gotAssignment;
}
示例7: getFirstPressedButton
private Boolean getFirstPressedButton(System.Windows.Forms.Form parent, ControllerData controllerData, ButtonAssignment buttonAssignment)
{
Boolean gotAssignment = false;
if (controllerData.guid == NETWORK_CONSOLE_CONTROLLER_GUID)
{
PCarsUDPreader gameDataReader = (PCarsUDPreader)GameStateReaderFactory.getInstance().getGameStateReader(GameDefinition.pCarsNetwork);
int assignedButton = gameDataReader.getButtonIndexForAssignment();
if (assignedButton != -1)
{
removeAssignmentsForControllerAndButton(controllerData.guid, assignedButton);
buttonAssignment.controller = controllerData;
buttonAssignment.buttonIndex = assignedButton;
listenForAssignment = false;
gotAssignment = true;
}
}
else
{
listenForAssignment = true;
// Instantiate the joystick
var joystick = new Joystick(directInput, controllerData.guid);
// Acquire the joystick
joystick.SetCooperativeLevel(parent, (CooperativeLevel.NonExclusive | CooperativeLevel.Background));
joystick.Properties.BufferSize = 128;
joystick.Acquire();
while (listenForAssignment)
{
Boolean[] buttons = joystick.GetCurrentState().Buttons;
for (int i = 0; i < buttons.Count(); i++)
{
if (buttons[i])
{
Console.WriteLine("Got button at index " + i);
removeAssignmentsForControllerAndButton(controllerData.guid, i);
buttonAssignment.controller = controllerData;
buttonAssignment.joystick = joystick;
buttonAssignment.buttonIndex = i;
listenForAssignment = false;
gotAssignment = true;
}
}
}
if (!gotAssignment)
{
joystick.Unacquire();
}
}
return gotAssignment;
}