您的位置:首页 > 移动开发 > Android开发

android 应用模拟按键

2010-06-20 10:03 471 查看
private void simulateKeystroke(int KeyCode) {

doInjectKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyCode));

doInjectKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyCode));

}

private void doInjectKeyEvent(KeyEvent kEvent) {

try {

/* Inject the KeyEvent to the Window-Manager. */

/* The WindowManager capable of injecting keyStrokes. */

final IWindowManager windowManager = IWindowManager.Stub

.asInterface(ServiceManager.getService("window"));

windowManager.injectKeyEvent(kEvent.isDown(), kEvent.getKeyCode(),

kEvent.getRepeatCount(), kEvent.getDownTime(), kEvent

.getEventTime(), true);

} catch (DeadObjectException e) {

e.printStackTrace();

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: