切换操纵杆USB端口时使用joyGetPosEx失败
我正在使用“joyGetPosEx”函数来检测操纵杆输入:
JOYINFOEX joyInfoEx;
ZeroMemory(&joyInfoEx, sizeof(joyInfoEx));
joyInfoEx.dwSize = sizeof(joyInfoEx);
// poll for values
joyGetPosEx(JOYSTICKID1, &joyInfoEx);
连接操纵杆时,一切正常,并且函数返回“JOYERR_NOERROR”。
但是,如果在程序运行期间,我断开操纵杆并将其连接到不同的 USB 端口, “joyGetPosEx(JOYSTICKID1, &joyInfoEx);”不断返回“JOYERR_UNPLUGGED”值。
如果我将设备重新连接到初始 USB 端口,它会再次开始工作。
有谁知道如何使操纵杆工作,即使它连接到新端口?
提前致谢!
I am using the "joyGetPosEx" function to detect the joystick inputs:
JOYINFOEX joyInfoEx;
ZeroMemory(&joyInfoEx, sizeof(joyInfoEx));
joyInfoEx.dwSize = sizeof(joyInfoEx);
// poll for values
joyGetPosEx(JOYSTICKID1, &joyInfoEx);
When the joystick is connected, every thing is working fine and the function returns "JOYERR_NOERROR".
However, if during the program run, i disconnect the joystick and connect it to a different USB port,
the "joyGetPosEx(JOYSTICKID1, &joyInfoEx);" keeps returning a "JOYERR_UNPLUGGED" value.
If i reconnect the device to the initial USB port, it srtarts working again.
Does any one know how to make the joystick work even if it gets connected to a new port?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想说您有一个没有序列号的 USB 设备,因此 Windows 通过插入位置来识别它。它是否会开始充当
JOYSTICKID2
?我们最终发现
joyConfigChanged
函数能够重新连接操纵杆。 [MSDN 说#include
是使用此函数所必需的,事实证明,包含的顺序很重要:首先是mmsystem.h
,然后是dinput.h
。I'd say you have a USB device with no serial number, so Windows identifies it by where it's plugged in. Does it start acting as
JOYSTICKID2
by any chance?We eventually discovered that the
joyConfigChanged
function is able to reconnect the joystick. [MSDN says that#include <dinput.h>
is necessary to use this function, as it turns out, the order of includes is important:mmsystem.h
first, thendinput.h
.