> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XInputGetKeystroke

> XInputGetKeystroke

# XInputGetKeystroke

Retrieves a gamepad input event.

## Syntax

```cpp theme={null}
DWORD XInputGetKeystroke(  
         DWORD dwUserIndex,  
         _Reserved_ dwReserved,  
         XINPUT_KEYSTROKE* pKeystroke  
)  
```

### Parameters

*dwUserIndex*   \_In\_\
Type: DWORD

Index of the signed-in gamer associated with the device. A value in the range of 0-XUSER\_MAX\_COUNT to 1; XUSER\_INDEX\_ANY is used to fetch the next available input event from any user.

*dwReserved*   \
Type: *Reserved*

This parameter is unused.

*pKeystroke*   \_Out\_\
Type: [XINPUT\_KEYSTROKE\*](/reference/input/xinputongameinput/structs/xinput_keystroke)

Pointer to an [XINPUT\_KEYSTROKE](/reference/input/xinputongameinput/structs/xinput_keystroke) structure that receives an input event.

### Return value

Type: DWORD

* If the function succeeds, it will return **ERROR\_SUCCESS**.
* If no new keys have been pressed, the function will return **ERROR\_EMPTY**.
* If the controller is not connected or the user has not activated it, the function will return **ERROR\_DEVICE\_NOT\_CONNECTED**; see the Remarks section below.
* If the function fails, it will return an error code defined in Winerror.h.

## Remarks

Wireless controllers are not considered active upon system startup; if a call is made to any of the XInput functions before a wireless controller is made active, that call will return **ERROR\_DEVICE\_NOT\_CONNECTED**. Game titles must examine the return code and must 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 Guide button to turn on the controller.

If the code you're porting from XInput to GameInput does not call the GetKeyStroke function, then you can reduce the size of the XInput wrapper by defining XINPUT\_ON\_GAMEINPUT\_NO\_XINPUTGETKEYSTROKE. For more information, see [Porting from XInput to GameInput](/build/core-features/common/input/porting/input-porting-xinput#optimizingSection).

## Requirements

**Header:** XInputOnGameInput.h

**Library:** xgameruntime.lib

**Supported platforms:** XBOX One family consoles and XBOX Series consoles

## See also

[Port XInput to GameInput](/build/core-features/common/input/porting/input-porting-xinput)\
[XInputOnGameInput](/reference/input/xinputongameinput/xinputongameinput_members)


## Related topics

- [XINPUT_KEYSTROKE](/reference/input/xinputongameinput/structs/xinput_keystroke.md)
- [XInputOnGameInput](/reference/input/xinputongameinput/xinputongameinput_members.md)
- [Porting from XInput to GameInput](/build/core-features/common/input/porting/input-porting-xinput.md)
- [GameInputDeviceInfo](/reference/input/gameinput/structs/gameinputdeviceinfo.md)
- [GameInputKeyboardInfo](/reference/input/gameinput/structs/gameinputkeyboardinfo.md)
