SlimDX:Joystick.Poll()成功上断开手柄手柄、SlimDX、Joystick、Poll

由网友(炊烟醉清风)分享简介:我有一个奇怪的问题SlimDX:我们已经在Windows 7上看到了这一点,并没有测试过其他版本:我使用的是廉价的USB游戏手柄捆绑(无序列号),和有时候一个物理游戏手柄最终提供输入到多个操纵杆对象。 I've got a curious problem with SlimDX: we've seen this on...

我有一个奇怪的问题SlimDX:我们已经在Windows 7上看到了这一点,并没有测试过其他版本:我使用的是廉价的USB游戏手柄捆绑(无序列号),和有时候一个物理游戏手柄最终提供输入到多个操纵杆对象。

I've got a curious problem with SlimDX: we've seen this on Windows 7, and haven't yet tested other versions: I'm using a bundle of cheap USB gamepads (no serial number), and sometimes one physical gamepad ends up providing the input to more than one Joystick object.

该方案是:

插入手柄1到集线器插槽1垫出现在 DirectInput.GetDevices 的GUID f17b2d30。对于垫创建操纵杆对象。 插入手柄2轮毂插槽2垫出现在 DirectInput.GetDevices 的GUID 5187d2d0。对于垫创建操纵杆对象。 preSS的手柄2.不改变状态的按钮。 preSS手柄上的一个按钮1.按钮出现在 GetCurrentState()设置民意测验()在这两个对象。 在拔出手柄2. 民意测验()其对象的方法继续运行而不返回错误,但不会再出现在 DirectInput.GetDevices 。 preSS手柄上的一个按钮1.按钮出现在 GetCurrentState()设置民意测验()在这两个对象。 Plug in gamepad 1 to hub slot 1. Pad appears in DirectInput.GetDevices as GUID f17b2d30. Create Joystick object for pad. Plug in gamepad 2 to hub slot 2. Pad appears in DirectInput.GetDevices as GUID 5187d2d0. Create Joystick object for pad. Press a button on gamepad 2. No change to state. Press a button on gamepad 1. Button appears set in GetCurrentState() after Poll() on both objects. Unplug gamepad 2. Poll() method on its object continues to return without error, but it no longer appears in DirectInput.GetDevices. Press a button on gamepad 1. Button appears set in GetCurrentState() after Poll() on both objects.

我已经研究在调试器中的对象。通过 Information.InstanceGUID 每个操纵杆引用了正确的GUID,但每个人都有相同的USB路径 Properties.InterfacePath

I've examined the objects in the debugger. Each Joystick references the correct GUID by Information.InstanceGUID, but each has the same USB path in Properties.InterfacePath.

游戏手柄的硬件,似乎一切正常 - 如果我在控制面板操纵杆测试仪执行相同的序列中的游戏手柄仍然是不同的。

The gamepad hardware seems to be working correctly - If I perform the same sequence with the control panel joystick tester the gamepads remain distinct.

的的DirectInput的GUID似乎基于USB PID和VID,然后顺序相同游戏手柄被插入,而不是物理路径USB端口它们插入到要被分配。如果我混用不同型号的手柄中,问题消失了。

The DirectInput GUIDs seem to be allocated based on the USB PID and VID, then the order the identical gamepads are plugged in, rather than the physical path to USB port they're plugged in to. If I mix different models of gamepad, the problem goes away.

这感觉就像一个SlimDX甚至DirectInput的错误 - ?有没有一种解决方法

It feels like a SlimDX or even a DirectInput bug - is there a workaround for this?

推荐答案

我在这里的最后的答案是完全放弃的DirectInput,并移动到RawInput。我实现了一个小的C DLL之间我的C#code和RawInput接口。

My final answer here was to drop DirectInput altogether, and move to RawInput. I implemented a small C DLL to interface between my C# code and RawInput.

我有两个限制:trouble找到设备名称和a在XP下崩溃读取设备信息。这些都不是我的应用程序的一个关键问题。

I've had two limitations: trouble finding device names, and a crash reading device information under XP. Neither of these are a critical problem for my application.

样品C ++源$ C ​​$ c是有点长,以适应一个答案,所以这里。

Sample C++ source code is a bit long to fit in an answer, so is here.

从C#调用使用这些签名:

Calling from C# uses these signatures:

    [DllImport("Adapters.dll", CallingConvention = CallingConvention.Cdecl)]
    private static extern int InitialiseGamepads(IntPtr hwnd);
    [DllImport("Adapters.dll", CallingConvention = CallingConvention.Cdecl)]
    private static extern IntPtr GetDevicePath(int index);
    [DllImport("Adapters.dll", CallingConvention = CallingConvention.Cdecl)]
    private static extern int PollDeviceChange();
    [DllImport("Adapters.dll", CallingConvention = CallingConvention.Cdecl)]
    private static extern int ProcessInput(IntPtr wParam, IntPtr lParam,
        out byte buttons, out int x, out int y);
阅读全文

相关推荐

最新文章