android 模拟鼠标/按键事件

http://panccp.blog.163.com/blog/static/2655604420136410200232/

Instrumentation发送键盘鼠标事件:Instrumentation提供了丰富的以send开头的函数接口来实现模拟键盘鼠标,如下所述:
sendCharacterSync(int keyCode)            //用于发送指定KeyCode的按键
sendKeyDownUpSync(int key)                //用于发送指定KeyCode的按键
sendPointerSync(MotionEvent event)     //用于模拟Touch
sendStringSync(String text)                   //用于发送字符串
 
    Instrumentation inst=new Instrumentation();
                     inst.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 10, 10, 0));
                     inst.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, 10, 10, 0));

你可能感兴趣的:(android 模拟鼠标/按键事件)