> ## 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.

# IGameInputReading::GetKeyState

> IGameInputReading::GetKeyState

# IGameInputReading::GetKeyState

Retrieves the state of active keys on a keyboard input.

## Syntax

```cpp theme={null}
uint32_t GetKeyState(
    uint32_t stateArrayCount,
    GameInputKeyState* stateArray
);
```

### Parameters

*stateArrayCount*   \_In\_\
Type: uint32\_t

Returns the number of keys active on a keyboard. This is acquired by calling the [IGameInputReading::GetKeyCount](/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_getkeycount) method.

*stateArray*   \_Out\_writes\_(stateArrayCount)
Type: [GameInputKeyState\*](/reference/input/gameinput/structs/gameinputkeystate)

Pointer to the [GameInputKeyState\*](/reference/input/gameinput/structs/gameinputkeystate) structure.

### Return value

Type: uint32\_t

Number of valid buffer entries.

## Remarks

The `IGameInputReading::GetKeyState` method retrieves the state of active keys on a game controller input. Rudimentary keyboard state is meant solely for mapping keyboard input to game actions, like movement or firing a weapon. It is not meant for regular text input. A game needs a significant amount of code on top of this state to implement something as simple as a text box (to say nothing of complex features like IMEs). Other APIs should be used where that functionality is desired.

The state for each key is not stored at a fixed index within the array. Rather, the number of valid elements in the array grows as keys are pressed and shrinks as keys are released. New keys are added at the end of the array, and when a key is released everything shifts down to fill the gap. The first array element where the `scancode` and `vkey` values are both zero. This indicates the end of valid data in the array. Standard keyboards are only able to report four to six key presses at a time, and even high-end gaming keyboards rarely support more than 12-16 keys at once. As such, this approach typically keeps the maximum size of the array small (the maximum size can be queried via the `IGameInputDevice` interface). This is much more efficient than having applications iterate over an array of 256 values every time they check the keyboard state.

## Requirements

**Header:** GameInput.h

[Advanced GameInput topics](/build/core-features/common/input/advanced/input-advanced-topics)\
[Overview of GameInput](/build/core-features/common/input/overviews/input-overview)\
[IGameInputReading](/reference/input/gameinput/interfaces/igameinputreading/igameinputreading)

## Version History

| Version | Changes     |
| ------- | ----------- |
| **v0**  | Introduced. |


## Related topics

- [IGameInputReading::GetKeyCount](/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_getkeycount.md)
- [GameInputKeyState](/reference/input/gameinput/structs/gameinputkeystate.md)
- [IGameInputReading::GetGamepadState](/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_getgamepadstate.md)
- [IGameInputReading::GetSensorsState](/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_getsensorsstate.md)
- [IGameInputReading::GetMouseState](/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_getmousestate.md)
