3

XInputGetKeyStroke seems to return ERROR_SUCCESS when the specified controller is not plugged in, leaving the supplied XINPUT_KEYSTROKE struct uninitialized:

XINPUT_KEYSTROKE xStroke;
DWORD ret = XInputGetKeyStroke(0, 0, &xStroke);
if (ret == ERROR_SUCCESS)
    printf("ERROR_SUCCESS\n");

Am I doing something wrong or is this a bug in XInput? xinput1_3.dll is the version I am using. I am compiling/linking against the headers/libraries in the DirectX 2010 SDK. When the controller is plugged in XInputGetKeyStrokes seems to behave as expected.

zdd
  • 8,258
  • 8
  • 46
  • 75

2 Answers2

0

I've had the same problem with xinput1_3.dll and from my research it seems it is not implemented. It may be implemented on xinput1_4.dll on Windows 8 but I am unable to test this.

Confirmation that it's not implemented as of 26th April 2014: http://controllermax.com/forums/archive/index.php/t-142531.html

Not the most acceptable of sources but it's all I could find.

ffhighwind
  • 165
  • 4
  • 13
0

Support for XInputGetKeyStroke was added for XInput 1.3 (April 2007), but no Windows driver supports the 'Chatpad' device so it's limited to the controller "button keys".

The source for this function did not change between XInput 1.3 (the last version available down-level on Windows 7 via the legacy DirectX SDK / DirectSetup) and XInput 1.4 (the current version on Windows 8.x), so if there is a bug here it likely repros on XInput 1.4 as well.

This particular API is really only useful on Xbox 360 where the 'Chatpad' might be supported, and due to the down-level story for XInput, you are usually better served using XInput 9.1.0 rather than XInput 1.3 and sticking with the standard XInputGetState methods anyhow. I don't use XInputGetKeyStroke at all for the DirectX Tool Kit GamePad class which is probably a more useful abstraction.

See XINPUT and Windows 8 and DirectX Tool Kit: Now with GamePads

UPDATE: I found the code path that resulted in this condition, and will file a bug, but it's not likely to get fixed for XInput 1.3. One workaround would be to use another function (XInputGetState or XInputGetCapabilities) to check for connected state, and then call XInputGetKeyStroke only if it is connected.

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81