Skip to content

Most visited

Recently visited




public class InputDriverEvent
extends Object


An event to send to an 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

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

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

 event.setPosition(MotionEvent.AXIS_X, 10);
 event.setPosition(MotionEvent.AXIS_Y, 5);

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

 event.setKeyPressed(KeyEvent.KEYCODE_B, false);

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() 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.


Public constructors



Public methods

void clear()

Clear the event.

void setContact(boolean contact)

Sets the contact state of the positional input.

void setKeyPressed(int code, boolean pressed)

Sets a key state.

void setPosition(int axis, int value)

Sets a position along an axis.

Inherited methods

From class java.lang.Object

Public constructors


InputDriverEvent ()

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

Public methods


void clear ()

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


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.

contact boolean: true if an input tool is in contact with the device.


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.

code int: A key code representing the key being changed. Must be a value from KeyEvent.
pressed boolean: true if the key is pressed, false if released.
IllegalArgumentException if code is not a recognized key code.


void setPosition (int axis, 
                int value)

Sets a position along an axis.

axis int: One of the axis constants from MotionEvent. Currently only X and Y are supported.
value int: The position along that axis.
IllegalArgumentException if axis is not supported.
This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields


Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (April 2018 — Developer Survey)