本文整理汇总了C#中Device.SetHat方法的典型用法代码示例。如果您正苦于以下问题:C# Device.SetHat方法的具体用法?C# Device.SetHat怎么用?C# Device.SetHat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Device
的用法示例。
在下文中一共展示了Device.SetHat方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: QueryDeviceCaps
bool QueryDeviceCaps(Device stick)
{
Debug.Print("[{0}] Querying joystick {1}",
TypeName, stick.GetGuid());
try
{
Debug.Indent();
HidProtocolCaps caps;
if (GetPreparsedData(stick.Handle, ref PreparsedData) &&
GetDeviceCaps(stick, PreparsedData, out caps))
{
if (stick.AxisCaps.Count >= JoystickState.MaxAxes ||
stick.ButtonCaps.Count >= JoystickState.MaxButtons)
{
Debug.Print("Device {0} has {1} and {2} buttons. This might be a touch device - skipping.",
stick.Handle, stick.AxisCaps.Count, stick.ButtonCaps.Count);
return false;
}
for (int i = 0; i < stick.AxisCaps.Count; i++)
{
Debug.Print("Analyzing value collection {0} {1} {2}",
i,
stick.AxisCaps[i].IsRange ? "range" : "",
stick.AxisCaps[i].IsAlias ? "alias" : "");
if (stick.AxisCaps[i].IsRange || stick.AxisCaps[i].IsAlias)
{
Debug.Print("Skipping value collection {0}", i);
continue;
}
HIDPage page = stick.AxisCaps[i].UsagePage;
short collection = stick.AxisCaps[i].LinkCollection;
switch (page)
{
case HIDPage.GenericDesktop:
HIDUsageGD gd_usage = (HIDUsageGD)stick.AxisCaps[i].NotRange.Usage;
switch (gd_usage)
{
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);
//.........这里部分代码省略.........
示例2: UpdateAxes
unsafe void UpdateAxes(RawInput* rin, Device stick)
{
for (int i = 0; i < stick.AxisCaps.Count; i++)
{
if (stick.AxisCaps[i].IsRange)
{
Debug.Print("[{0}] Axis range collections not implemented. Please report your controller type at http://www.opentk.com",
GetType().Name);
continue;
}
HIDPage page = stick.AxisCaps[i].UsagePage;
short usage = stick.AxisCaps[i].NotRange.Usage;
uint value = 0;
short collection = stick.AxisCaps[i].LinkCollection;
HidProtocolStatus status = HidProtocol.GetUsageValue(
HidProtocolReportType.Input,
page, 0, usage, ref value,
PreparsedData,
new IntPtr((void*)&rin->Data.HID.RawData),
rin->Data.HID.Size);
if (status != HidProtocolStatus.Success)
{
Debug.Print("[{0}] HidProtocol.GetScaledUsageValue() failed. Error: {1}",
GetType().Name, status);
continue;
}
if (page == HIDPage.GenericDesktop && (HIDUsageGD)usage == HIDUsageGD.Hatswitch)
{
stick.SetHat(collection, page, usage, GetHatPosition(value, stick.AxisCaps[i]));
}
else
{
short scaled_value = (short)HidHelper.ScaleValue(
(int)((long)value + stick.AxisCaps[i].LogicalMin),
stick.AxisCaps[i].LogicalMin, stick.AxisCaps[i].LogicalMax,
Int16.MinValue, Int16.MaxValue);
stick.SetAxis(collection, page, usage, scaled_value);
}
}
}