现在的位置: 首页 > 综合 > 正文

android 模拟鼠标/按键事件

2018年01月18日 ⁄ 综合 ⁄ 共 690字 ⁄ 字号 评论关闭

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));

抱歉!评论已关闭.