模拟按键:
1、 new Instrumentation().sendKeyDownUpSync(int keycode);
发送keycode,down,up都会发送一遍
2、 new Instrumentation().sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN, int mKeycode) ;
发送keycode,可以指定发送down,或者up
模拟屏幕点击
3、 new Instrumentation().sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_MOVE, x, y, 0);
4、ProcessBuilder pb = new ProcessBuilder("input tap " + x + " " + y);
pb.directory(new File("/system/bin"));
pb.start();
以上方法只能在当前的应用里面模拟按键和屏幕点击,如果要实现全局的模拟按键需要系统权限才能执行。