public class

EventSender

extends Object
java.lang.Object
   ↳ com.davidluoye.support.util.EventSender

Summary

Fields
public static final int INJECT_INPUT_EVENT_MODE_ASYNC Input Event Injection Synchronization Mode: None.
public static final int INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH Input Event Injection Synchronization Mode: Wait for finish.
public static final int INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT Input Event Injection Synchronization Mode: Wait for result.
Public Constructors
EventSender()
Public Methods
static void sendCharacterSync(int keyCode)
Higher-level method for sending both the down and up key events for a particular character key code.
static void sendKeyDownUpSync(int key)
Sends an up and down key event sync to the currently focused window.
static void sendKeySync(KeyEvent event)
Send a key event to the currently focused window/view and wait for it to be processed.
static void sendPointerSync(MotionEvent event)
Dispatch a pointer event.
static void sendStringSync(String text)
Sends the key events corresponding to the text to the app being instrumented.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

public static final int INJECT_INPUT_EVENT_MODE_ASYNC

Input Event Injection Synchronization Mode: None. Never blocks. Injection is asynchronous and is assumed always to be successful.

public static final int INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH

Input Event Injection Synchronization Mode: Wait for finish. Waits for the event to be delivered to the application and handled.

public static final int INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT

Input Event Injection Synchronization Mode: Wait for result. Waits for previous events to be dispatched so that the input dispatcher can determine whether input event injection will be permitted based on the current input focus. Does not wait for the input event to finish being handled by the application.

Public Constructors

public EventSender ()

Public Methods

public static void sendCharacterSync (int keyCode)

Higher-level method for sending both the down and up key events for a particular character key code. Equivalent to creating both KeyEvent objects by hand and calling sendKeySync(KeyEvent). The event appears as if it came from keyboard 0, the built in one.

Parameters
keyCode The key code of the character to send.

public static void sendKeyDownUpSync (int key)

Sends an up and down key event sync to the currently focused window.

Parameters
key The integer keycode for the event.

public static void sendKeySync (KeyEvent event)

Send a key event to the currently focused window/view and wait for it to be processed. Finished at some point after the recipient has returned from its event processing, though it may not have completely finished reacting from the event -- for example, if it needs to update its display as a result, it may still be in the process of doing that.

Parameters
event The event to send to the current focus.

public static void sendPointerSync (MotionEvent event)

Dispatch a pointer event. Finished at some point after the recipient has returned from its event processing, though it may not have completely finished reacting from the event -- for example, if it needs to update its display as a result, it may still be in the process of doing that.

Parameters
event A motion event describing the pointer action. (As noted in obtain(long, long, int, float, float, int), be sure to use uptimeMillis() as the timebase.

public static void sendStringSync (String text)

Sends the key events corresponding to the text to the app being instrumented.

Parameters
text The text to be sent.