本文整理汇总了C#中Device.SetButton方法的典型用法代码示例。如果您正苦于以下问题:C# Device.SetButton方法的具体用法?C# Device.SetButton怎么用?C# Device.SetButton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Device
的用法示例。
在下文中一共展示了Device.SetButton方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: QueryDeviceCaps
//.........这里部分代码省略.........
case HIDUsageGD.X:
case HIDUsageGD.Y:
case HIDUsageGD.Z:
case HIDUsageGD.Rx:
case HIDUsageGD.Ry:
case HIDUsageGD.Rz:
case HIDUsageGD.Slider:
case HIDUsageGD.Dial:
case HIDUsageGD.Wheel:
Debug.Print("Found axis {0} ({1} / {2})",
JoystickAxis.Axis0 + stick.GetCapabilities().AxisCount,
page, (HIDUsageGD)stick.AxisCaps[i].NotRange.Usage);
stick.SetAxis(collection, page, stick.AxisCaps[i].NotRange.Usage, 0);
break;
case HIDUsageGD.Hatswitch:
Debug.Print("Found hat {0} ({1} / {2})",
JoystickHat.Hat0 + stick.GetCapabilities().HatCount,
page, (HIDUsageGD)stick.AxisCaps[i].NotRange.Usage);
stick.SetHat(collection, page, stick.AxisCaps[i].NotRange.Usage, HatPosition.Centered);
break;
default:
Debug.Print("Unknown usage {0} for page {1}",
gd_usage, page);
break;
}
break;
case HIDPage.Simulation:
switch ((HIDUsageSim)stick.AxisCaps[i].NotRange.Usage)
{
case HIDUsageSim.Rudder:
case HIDUsageSim.Throttle:
Debug.Print("Found simulation axis {0} ({1} / {2})",
JoystickAxis.Axis0 + stick.GetCapabilities().AxisCount,
page, (HIDUsageSim)stick.AxisCaps[i].NotRange.Usage);
stick.SetAxis(collection, page, stick.AxisCaps[i].NotRange.Usage, 0);
break;
}
break;
default:
Debug.Print("Unknown page {0}", page);
break;
}
}
for (int i = 0; i < stick.ButtonCaps.Count; i++)
{
Debug.Print("Analyzing button collection {0} {1} {2}",
i,
stick.ButtonCaps[i].IsRange ? "range" : "",
stick.ButtonCaps[i].IsAlias ? "alias" : "");
if (stick.ButtonCaps[i].IsAlias)
{
Debug.Print("Skipping button collection {0}", i);
continue;
}
bool is_range = stick.ButtonCaps[i].IsRange;
HIDPage page = stick.ButtonCaps[i].UsagePage;
short collection = stick.ButtonCaps[i].LinkCollection;
switch (page)
{
case HIDPage.Button:
if (is_range)
{
for (short usage = stick.ButtonCaps[i].Range.UsageMin; usage <= stick.ButtonCaps[i].Range.UsageMax; usage++)
{
Debug.Print("Found button {0} ({1} / {2})",
JoystickButton.Button0 + stick.GetCapabilities().ButtonCount,
page, usage);
stick.SetButton(collection, page, usage, false);
}
}
else
{
Debug.Print("Found button {0} ({1} / {2})",
JoystickButton.Button0 + stick.GetCapabilities().ButtonCount,
page, stick.ButtonCaps[i].NotRange.Usage);
stick.SetButton(collection, page, stick.ButtonCaps[i].NotRange.Usage, false);
}
break;
default:
Debug.Print("Unknown page {0} for button.", page);
break;
}
}
}
}
finally
{
Debug.Unindent();
}
return true;
}
示例2: UpdateButtons
unsafe void UpdateButtons(RawInput* rin, Device stick)
{
stick.ClearButtons();
for (int i = 0; i < stick.ButtonCaps.Count; i++)
{
short* usage_list = stackalloc short[(int)JoystickButton.Last + 1];
int usage_length = (int)JoystickButton.Last;
HIDPage page = stick.ButtonCaps[i].UsagePage;
short collection = stick.ButtonCaps[i].LinkCollection;
HidProtocolStatus status = HidProtocol.GetUsages(
HidProtocolReportType.Input,
page, 0, usage_list, ref usage_length,
PreparsedData,
new IntPtr((void*)&rin->Data.HID.RawData),
rin->Data.HID.Size);
if (status != HidProtocolStatus.Success)
{
Debug.Print("[WinRawJoystick] HidProtocol.GetUsages() failed with {0}",
Marshal.GetLastWin32Error());
continue;
}
for (int j = 0; j < usage_length; j++)
{
short usage = *(usage_list + j);
stick.SetButton(collection, page, usage, true);
}
}
}