Android 实现模拟按键方法二

来源:互联网 发布:matlab plot画数组 编辑:程序博客网 时间:2024/06/07 04:09

通过Runtime实现模拟按键,但速度很慢。


用Instrumentation效果不错

 new Thread () {
            public void run () {
                try {
                   Instrumentation inst=new Instrumentation();
                   inst.sendKeyDownUpSync(4);
                } catch(Exception e) {
                        Log.e("Exception when sendPointerSync", e.toString());
                }
            }
        }.start();