XInputGetKeystroke

Retrieves a gamepad input event.

DWORD XInputGetKeystroke(
  DWORD dwUserIndex,
  DWORD dwFlags,
  PXINPUT_KEYSTROKE pKeystroke
);

Parameters

dwUserIndex
[in] Index of the signed-in gamer associated with the device. Can be a value in the range 0–XUSER_MAX_COUNT − 1, or XUSER_INDEX_ANY to fetch the next available input event from any user.
dwFlags
[in] Input flags that identify the device type. Permissible values to limit the input event fetch are shown in the following table.
Value Description
XINPUT_FLAG_GAMEPAD Limit input event fetch to the gamepad.
XINPUT_FLAG_KEYBOARD Limit input event fetch to the keyboard.
XINPUT_FLAG_REMOTE Limit input event fetch to the infrared remote.
XINPUT_FLAG_ANYDEVICE Fetch input event from any device.
XINPUT_FLAG_ANYUSER Fetch input event from any device when dwUserIndex is XUSER_INDEX_ANY.
pKeystroke
[out] Pointer to an XINPUT_KEYSTROKE structure that receives an input event.

Return Values

If the function succeeds, the return value is ERROR_SUCCESS.

If no new keys have been pressed, the return value is ERROR_EMPTY.

If the controller is not connected or the user has not activated it, the return value is ERROR_DEVICE_NOT_CONNECTED. (See Remarks.)

If the function fails, the return value is an error code defined in Winerror.h. The function does not use SetLastError to set the calling thread's last-error code.

Remarks

Wireless controllers are not considered active upon system startup, and calls to any of the XInput functions before a wireless controller is made active return ERROR_DEVICE_NOT_CONNECTED. Game titles must examine the return code and be prepared to handle this condition. Wired controllers are automatically activated when they are inserted. Wireless controllers are activated when the user presses the START or Xbox Guide button to power on the controller.

The functions XInputGetCapabilities, XInputGetState, and XInputGetKeystroke ignore the port number if XDEVICE_PORT_FLAG_KEYBOARD is specified. If this flag is specified, the same debug keyboard appears to be plugged into all four ports.

Requirements

Header: Declared in XInput.h.

Import Library: Use Xinput.lib.

See Also

XInput Functions | XINPUT_KEYSTROKE