开发者

Using joyGetPosEx fails when switching joystick USB port

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 US开发者_运维百科B 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!


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, then dinput.h.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜