# InputDriverEvent

Summary:[Ctors](https://developer.android.com/reference/com/google/android/things/userdriver/input/InputDriverEvent#pubctors)\|[Methods](https://developer.android.com/reference/com/google/android/things/userdriver/input/InputDriverEvent#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/com/google/android/things/userdriver/input/InputDriverEvent#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/com/google/android/things/userdriver/input/InputDriverEvent#)  

# InputDriverEvent

`
public


class
InputDriverEvent
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|-------------------------------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | com.google.android.things.userdriver.input.InputDriverEvent |

<br />

*** ** * ** ***

An event to send to an[InputDriver](https://developer.android.com/reference/com/google/android/things/userdriver/input/InputDriver). A single event reflects a change in state of one or more components (buttons, motion axes, etc.) of the driver, all happening since the last event.

### Usage Example

<br />


     InputDriver driver = ...;  // See InputDriver class.
     InputDriverEvent event = new InputDriverEvent();

     event.setKeyPressed(KeyEvent.KEYCODE_A, true);
     event.setKeyPressed(KeyEvent.KEYCODE_B, true);
     driver.emit(event)

     event.clear();
     event.setPosition(MotionEvent.AXIS_X, 10);
     event.setPosition(MotionEvent.AXIS_Y, 5);
     event.setContact(true);
     driver.emit(event);

     event.clear();
     event.setPosition(MotionEvent.AXIS_X, 5);
     event.setKeyPressed(KeyEvent.KEYCODE_A, false);
     driver.emit(event);

     event.clear();
     event.setContact(false);
     event.setKeyPressed(KeyEvent.KEYCODE_B, false);
     driver.emit(event);
     
<br />

This describes a sequence of 4 moments in time: 1) A and B keys were pressed. 2) Positional contact was made at (10,5) 3) Contact moved to (5,5), A key was released. 4) Contact and B key were released. Notice that components not explicitly changed are assumed to stay in the same state.

### Clearing Events

Given that components not explicitly changed are assumed to maintain state, it's best practice, but not strictly necessary, to call[clear()](https://developer.android.com/reference/com/google/android/things/userdriver/input/InputDriverEvent#clear())between emissions. This will only matter if the same event is emitted via multiple drivers, or with a different event between emissions via the same driver, because state is driver-specific. Clearing before each re-use helps avoid potential mix ups if drawing from a common pool of event objects.

<br />

## Summary

|                                                                      ### Public constructors                                                                       ||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[InputDriverEvent](https://developer.android.com/reference/com/google/android/things/userdriver/input/InputDriverEvent#InputDriverEvent())`() ` Constructor. |

|                                                                                                  ### Public methods                                                                                                   ||
|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void` | ` `[clear](https://developer.android.com/reference/com/google/android/things/userdriver/input/InputDriverEvent#clear())`() ` Clear the event.                                                                |
| ` void` | ` `[setContact](https://developer.android.com/reference/com/google/android/things/userdriver/input/InputDriverEvent#setContact(boolean))`(boolean contact) ` Sets the contact state of the positional input. |
| ` void` | ` `[setKeyPressed](https://developer.android.com/reference/com/google/android/things/userdriver/input/InputDriverEvent#setKeyPressed(int, boolean))`(int code, boolean pressed) ` Sets a key state.          |
| ` void` | ` `[setPosition](https://developer.android.com/reference/com/google/android/things/userdriver/input/InputDriverEvent#setPosition(int, int))`(int axis, int value) ` Sets a position along an axis.           |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/com/google/android/things/userdriver/input/InputDriverEvent#)From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                                                                                                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                                                                                                                                                                                                                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                                                                                                                                                                                                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                                                                                                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                                                                                                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                                                                                                                                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                                                                                                                                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                                                                                                                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long, int))`(long millis, int nanos) ` Causes the current thread to wait until another thread invokes the[notify()](https://developer.android.com/reference/java/lang/Object.html#notify())method or the[notifyAll()](https://developer.android.com/reference/java/lang/Object.html#notifyAll())method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long millis) ` Causes the current thread to wait until either another thread invokes the[notify()](https://developer.android.com/reference/java/lang/Object.html#notify())method or the[notifyAll()](https://developer.android.com/reference/java/lang/Object.html#notifyAll())method for this object, or a specified amount of time has elapsed.                                                                 | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until another thread invokes the[notify()](https://developer.android.com/reference/java/lang/Object.html#notify())method or the[notifyAll()](https://developer.android.com/reference/java/lang/Object.html#notifyAll())method for this object.                                                                                                                                  | ||

## Public constructors

### InputDriverEvent

```
InputDriverEvent ()
```

Constructor. Creates a new event with no state changes (until state setters are called).

<br />

## Public methods

### clear

```
void clear ()
```

Clear the event. After this call, the event will indicate no state changes (until state setters are called).

<br />

### setContact

```
void setContact (boolean contact)
```

Sets the contact state of the positional input. Used to indicate when an input tool (e.g. finger or stylus) is determined to be within meaningful physical contact with the positional input device. "Meaningful" is up to the driver implementer; it could be any contact, or it could be some pressure threshold.

<br />

|                                    Parameters                                     ||
|-----------|------------------------------------------------------------------------|
| `contact` | `boolean`: true if an input tool is in contact with the device. <br /> |

### setKeyPressed

```
void setKeyPressed (int code, 
                boolean pressed)
```

Sets a key state. Multiple keys can have their state updated in a single event, simply call this method for each of them.

<br />

|                                                                                 Parameters                                                                                  ||
|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `code`    | `int`: A key code representing the key being changed. Must be a value from[KeyEvent](https://developer.android.com/reference/android/view/KeyEvent.html). <br /> |
| `pressed` | `boolean`: true if the key is pressed, false if released. <br />                                                                                                 |

|                                                                    Throws                                                                     ||
|--------------------------------------------------------------------------------------------------------|---------------------------------------|
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | if code is not a recognized key code. |

### setPosition

```
void setPosition (int axis, 
                int value)
```

Sets a position along an axis.

<br />

|                                                                                    Parameters                                                                                    ||
|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `axis`  | `int`: One of the axis constants from[MotionEvent](https://developer.android.com/reference/android/view/MotionEvent.html). Currently only X and Y are supported. <br /> |
| `value` | `int`: The position along that axis. <br />                                                                                                                             |

|                                                              Throws                                                               ||
|--------------------------------------------------------------------------------------------------------|---------------------------|
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | if axis is not supported. |

-

  ## Classes

  - [InputDriver](https://developer.android.com/reference/com/google/android/things/userdriver/input/InputDriver)
  - [InputDriver.Builder](https://developer.android.com/reference/com/google/android/things/userdriver/input/InputDriver.Builder)
  - [InputDriverEvent](https://developer.android.com/reference/com/google/android/things/userdriver/input/InputDriverEvent)