Android: 发送虚拟按键

Android: 发送虚拟按键

/**    * Send a single key event.    *    * @param event is a string representing the keycode of the key event you    * want to execute.    */   private void sendKeyEvent(int keyCode) {       int eventCode = keyCode;       long now = SystemClock.uptimeMillis();       try {           KeyEvent down = new KeyEvent(now, now, KeyEvent.ACTION_DOWN, eventCode, 0);           KeyEvent up = new KeyEvent(now, now, KeyEvent.ACTION_UP, eventCode, 0);           (IWindowManager.Stub               .asInterface(ServiceManager.getService("window")))               .injectInputEventNoWait(down);           (IWindowManager.Stub               .asInterface(ServiceManager.getService("window")))               .injectInputEventNoWait(up);       } catch (RemoteException e) {           Log.i(TAG, "DeadOjbectException");       }   }  

sendKeyEvent(KeyEvent.KEYCODE_BACK);

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wyzgfd.html