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

# IGameInputReading::GetTouchSurfaceState

> Retrieves the contacts on a touch surface from an input reading.

Retrieves the contacts on a touch surface from an input reading.

## Syntax

```cpp theme={null}
uint32_t GetTouchSurfaceState(
    uint32_t surfaceIndex,
    uint32_t contactArrayCount,
    GameInputTouchContact* contactArray
);
```

### Parameters

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

Index of the touch surface. Must be less than the value returned by [IGameInputDevice::GetTouchSurfaceCount](https://docs.xbox.com/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_gettouchsurfacecount.md).

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

Number of elements in *contactArray*.

*contactArray*   \_Out\_writes\_to\_opt\_(contactArrayCount, return)\
Type: [GameInputTouchContact](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/structs/gameinputtouchcontact)\*

Array that receives the contacts on the touch surface. Can be null.

### Return value

Type: uint32\_t

If *contactArray* is null, returns the number of contacts on the touch surface. Otherwise, returns the number of contacts written to *contactArray*, which is the smaller of the number of contacts and *contactArrayCount*. Returns 0 if the reading doesn't contain touch data or if *surfaceIndex* isn't a valid surface index.

## Remarks

Each element of *contactArray* describes one contact, such as a finger, on the surface. Elements of *contactArray* that aren't written with a contact are set to zero. The `contactId` member of [GameInputTouchContact](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/structs/gameinputtouchcontact) stays the same for as long as the contact remains on the surface, so you can use it to track a contact across readings.

To size *contactArray*, call [IGameInputReading::GetTouchContactCount](https://docs.xbox.com/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_gettouchcontactcount.md), or use the `maxContactCount` member of [GameInputTouchSurfaceInfo](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/structs/gameinputtouchsurfaceinfo) to allocate an array that's large enough for any reading. To interpret the contact coordinates, call [IGameInputDevice::GetTouchSurfaceInfo](https://docs.xbox.com/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_gettouchsurfaceinfo.md) with the same surface index.

Readings that contain touch data include `GameInputKindTouch` in [IGameInputReading::GetInputKind](https://docs.xbox.com/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_getinputkind.md).

> [!NOTE]
>
> Touch support depends on the device and the platform.

The following example reads the contacts on every touch surface of a device.

```cpp theme={null}
void ReadTouchContacts(
    _In_ IGameInputDevice* device,
    _In_ IGameInputReading* reading) noexcept
{
    const uint32_t surfaceCount = device->GetTouchSurfaceCount();
    for (uint32_t surfaceIndex = 0; surfaceIndex < surfaceCount; ++surfaceIndex)
    {
        GameInputTouchSurfaceInfo surfaceInfo = {};
        if (FAILED(device->GetTouchSurfaceInfo(surfaceIndex, &surfaceInfo)))
        {
            continue;
        }

        std::vector<GameInputTouchContact> contacts(surfaceInfo.maxContactCount);
        const uint32_t contactCount = reading->GetTouchSurfaceState(
            surfaceIndex,
            static_cast<uint32_t>(contacts.size()),
            contacts.data());

        for (uint32_t i = 0; i < contactCount; ++i)
        {
            const GameInputTouchContact& contact = contacts[i];

            // Normalize the position to the range [0, 1].
            const float x = static_cast<float>(contact.padX) / static_cast<float>(surfaceInfo.padWidth);
            const float y = static_cast<float>(contact.padY) / static_cast<float>(surfaceInfo.padHeight);

            // Application-specific code to handle contact.contactId at (x, y)
        }
    }
}
```

## Requirements

**Header:** GameInput.h

**Library:** gameinput.lib

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

## See also

[Overview of GameInput](https://docs.xbox.com/build/core-features/common/input/overviews/input-overview.md)\
[IGameInputReading](https://docs.xbox.com/reference/input/gameinput/interfaces/igameinputreading/igameinputreading.md)\
[IGameInputReading::GetTouchContactCount](https://docs.xbox.com/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_gettouchcontactcount.md)\
[IGameInputDevice::GetTouchSurfaceInfo](https://docs.xbox.com/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_gettouchsurfaceinfo.md)\
[GameInputTouchContact](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/structs/gameinputtouchcontact)\
[GameInputTouchSurfaceInfo](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/structs/gameinputtouchsurfaceinfo)

## Version History

| Version | Changes |
| - | - |
| **v4** | Introduced. |


## Related topics

- [IGameInputReading::GetTouchContactCount](https://docs.xbox.com/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_gettouchcontactcount.md)
- [IGameInputDevice::GetTouchSurfaceInfo](https://docs.xbox.com/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_gettouchsurfaceinfo.md)
- [IGameInputDevice::GetTouchSurfaceCount](https://docs.xbox.com/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_gettouchsurfacecount.md)
- [GameInputKind](https://docs.xbox.com/reference/input/gameinput/enums/gameinputkind.md)
- [GameInput API Versioning](https://docs.xbox.com/build/core-features/common/input/overviews/input-versioning.md)
