Example usage for android.hardware.input InputManager injectInputEvent

List of usage examples for android.hardware.input InputManager injectInputEvent

Introduction

In this page you can find the example usage for android.hardware.input InputManager injectInputEvent.

Prototype

@UnsupportedAppUsage
public boolean injectInputEvent(InputEvent event, int mode) 

Source Link

Document

Injects an input event into the event system on behalf of an application.

Usage

From source file:com.android.tv.settings.accessories.AddAccessoryActivity.java

private void sendKeyEvent(int keyCode, boolean down) {
    InputManager iMgr = (InputManager) getSystemService(INPUT_SERVICE);
    if (iMgr != null) {
        long time = SystemClock.uptimeMillis();
        KeyEvent evt = new KeyEvent(time, time, down ? KeyEvent.ACTION_DOWN : KeyEvent.ACTION_UP, keyCode, 0);
        iMgr.injectInputEvent(evt, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
    }//  w w  w .  j  a  v  a2  s.c o  m
}