# KeyEvent.DispatcherState

Added in[API level 5](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# DispatcherState

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/view/KeyEvent.DispatcherState "View this page in Java")  

```
open class DispatcherState
```

|---|--------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                 ||
| ↳ | [android.view.KeyEvent.DispatcherState](https://developer.android.com/reference/kotlin/android/view/KeyEvent.DispatcherState#) |

Use with[KeyEvent.dispatch(Callback, DispatcherState, Object)](https://developer.android.com/reference/kotlin/android/view/KeyEvent#dispatch(android.view.KeyEvent.Callback,%20android.view.KeyEvent.DispatcherState,%20kotlin.Any))for more advanced key dispatching, such as long presses.

## Summary

|                                                           Public constructors                                                           ||
|--------------------------------------------------------------------------------------------------------------------------------------|---|
| [DispatcherState](https://developer.android.com/reference/kotlin/android/view/KeyEvent.DispatcherState#DispatcherState())`()` <br /> |

|                                                                                                                                                                                                                                             Public methods                                                                                                                                                                                                                                             ||
|----------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)       | [handleUpEvent](https://developer.android.com/reference/kotlin/android/view/KeyEvent.DispatcherState#handleUpEvent(android.view.KeyEvent))`(`event:` `[KeyEvent](https://developer.android.com/reference/kotlin/android/view/KeyEvent)!`)` Handle key up event to stop tracking.                                                                                                                               |
| open[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | [isTracking](https://developer.android.com/reference/kotlin/android/view/KeyEvent.DispatcherState#isTracking(android.view.KeyEvent))`(`event:` `[KeyEvent](https://developer.android.com/reference/kotlin/android/view/KeyEvent)!`)` Return true if the key event is for a key code that is currently being tracked by the dispatcher.                                                                         |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)       | [performedLongPress](https://developer.android.com/reference/kotlin/android/view/KeyEvent.DispatcherState#performedLongPress(android.view.KeyEvent))`(`event:` `[KeyEvent](https://developer.android.com/reference/kotlin/android/view/KeyEvent)!`)` Keep track of the given event's key code as having performed an action with a long press, so no action should occur on the up.                            |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)       | [reset](https://developer.android.com/reference/kotlin/android/view/KeyEvent.DispatcherState#reset())`()` Reset back to initial state.                                                                                                                                                                                                                                                                         |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)       | [reset](https://developer.android.com/reference/kotlin/android/view/KeyEvent.DispatcherState#reset(kotlin.Any))`(`target:` `[Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)!`)` Stop any tracking associated with this target.                                                                                                                                                      |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)       | [startTracking](https://developer.android.com/reference/kotlin/android/view/KeyEvent.DispatcherState#startTracking(android.view.KeyEvent,%20kotlin.Any))`(`event:` `[KeyEvent](https://developer.android.com/reference/kotlin/android/view/KeyEvent)!`, `target:` `[Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)!`)` Start tracking the key code associated with the given event. |

## Public constructors

### DispatcherState

```
DispatcherState()
```

## Public methods

### handleUpEvent

Added in[API level 5](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun handleUpEvent(event: KeyEvent!): Unit
```

Handle key up event to stop tracking. This resets the dispatcher state, and updates the key event state based on it.

This is only needed if you are directly dispatching events, rather than handling them in[Callback.onKeyUp](https://developer.android.com/reference/kotlin/android/view/KeyEvent.Callback#onKeyUp(kotlin.Int,%20android.view.KeyEvent)).  

### isTracking

Added in[API level 5](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun isTracking(event: KeyEvent!): Boolean
```

Return true if the key event is for a key code that is currently being tracked by the dispatcher.  

### performedLongPress

Added in[API level 5](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun performedLongPress(event: KeyEvent!): Unit
```

Keep track of the given event's key code as having performed an action with a long press, so no action should occur on the up.

This is only needed if you are directly dispatching events, rather than handling them in[Callback.onKeyLongPress](https://developer.android.com/reference/kotlin/android/view/KeyEvent.Callback#onKeyLongPress(kotlin.Int,%20android.view.KeyEvent)).  

### reset

Added in[API level 5](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun reset(): Unit
```

Reset back to initial state.  

### reset

Added in[API level 5](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun reset(target: Any!): Unit
```

Stop any tracking associated with this target.  

### startTracking

Added in[API level 5](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun startTracking(
    event: KeyEvent!, 
    target: Any!
): Unit
```

Start tracking the key code associated with the given event. This can only be called on a key down. It will allow you to see any long press associated with the key, and will result in[KeyEvent.isTracking](https://developer.android.com/reference/kotlin/android/view/KeyEvent#isTracking())return true on the long press and up events.

This is only needed if you are directly dispatching events, rather than handling them in[Callback.onKeyDown](https://developer.android.com/reference/kotlin/android/view/KeyEvent.Callback#onKeyDown(kotlin.Int,%20android.view.KeyEvent)).