# PointerCaptureComponent

Artifact: [androidx.xr.scenecore:scenecore](https://developer.android.com/jetpack/androidx/releases/xr-scenecore) [View Source](https://cs.android.com/search?q=file:androidx/xr/scenecore/PointerCaptureComponent.kt+class:androidx.xr.scenecore.PointerCaptureComponent) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

*** ** * ** ***


```
class PointerCaptureComponent : Component
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.xr.scenecore.Component](https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component) ||
|   | ↳ | [androidx.xr.scenecore.PointerCaptureComponent](https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PointerCaptureComponent) |

*** ** * ** ***

Provides pointer capture capabilities for a given `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`.

To enable pointer capture, the task must be in full space, the entity must be visible, and the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PointerCaptureComponent` must be attached to the entity.

Only one PointerCaptureComponent can be attached to an entity at a given time. If a second one tries to attach to an entity, it will fail.

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PointerCaptureComponent.PointerCaptureState` Defines the possible states of a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PointerCaptureComponent`. |

| ### Public companion functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PointerCaptureComponent` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PointerCaptureComponent#create(androidx.xr.runtime.Session,java.util.concurrent.Executor,java.util.function.Consumer,java.util.function.Consumer)( session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html, stateListener: https://developer.android.com/reference/java/util/function/Consumer.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PointerCaptureComponent.PointerCaptureState>, inputListener: https://developer.android.com/reference/java/util/function/Consumer.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/InputEvent> )` Creates a new instance of `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PointerCaptureComponent`. |

| ### Protected functions |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PointerCaptureComponent#onAttach(androidx.xr.scenecore.Entity)(entity: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity)` Called by the framework when this component is being added to an `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PointerCaptureComponent#onDetach(androidx.xr.scenecore.Entity)(entity: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity)` Called by the framework when this component is being removed from an `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`. |

## Public companion functions

### create

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
fun create(
    session: Session,
    executor: Executor,
    stateListener: Consumer<PointerCaptureComponent.PointerCaptureState>,
    inputListener: Consumer<InputEvent>
): PointerCaptureComponent
```

Creates a new instance of `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PointerCaptureComponent`.

| Parameters |
|---|---|
| `session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` | The active `https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` for the scene. |
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | The `https://developer.android.com/reference/java/util/concurrent/Executor.html` on which the listener callbacks will be invoked. |
| `stateListener: https://developer.android.com/reference/java/util/function/Consumer.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PointerCaptureComponent.PointerCaptureState>` | A `https://developer.android.com/reference/java/util/function/Consumer.html` to receive updates when the pointer capture state changes (e.g., from active to paused). |
| `inputListener: https://developer.android.com/reference/java/util/function/Consumer.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/InputEvent>` | A `https://developer.android.com/reference/java/util/function/Consumer.html` to receive all `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/InputEvent`s while pointer capture is active for the attached entity. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PointerCaptureComponent` | A new instance of `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PointerCaptureComponent`. |

## Protected functions

### onAttach

```
protected open fun onAttach(entity: Entity): Boolean
```

Called by the framework when this component is being added to an `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`.

This method is triggered when `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#addComponent(androidx.xr.scenecore.Component)` is invoked. Implementations should override this method to perform setup logic or to validate if the component is compatible with the provided `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component#onAttach(androidx.xr.scenecore.Entity)`.

| Parameters |
|---|---|
| `entity: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` | The `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` to which this component is being attached. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the component was successfully attached; `false` if the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component#onAttach(androidx.xr.scenecore.Entity)` does not support this component or if attachment failed. |

### onDetach

```
protected open fun onDetach(entity: Entity): Unit
```

Called by the framework when this component is being removed from an `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`.

This method is triggered when `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#removeComponent(androidx.xr.scenecore.Component)` is invoked. Implementations should override this method to release resources or undo any changes made during `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component#onAttach(androidx.xr.scenecore.Entity)`.

| Parameters |
|---|---|
| `entity: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` | The `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` from which this component is being detached. |