模拟按键和触摸
2016-01-21 17:22
471 查看
模拟按键:
模拟长按电源键:
触摸:
参考文章:http://blog.163.com/fanning_7213/blog/static/24965052011312113638776/
http://blog.sina.com.cn/s/blog_68f262210102vc1b.html
http://blog.sina.com.cn/s/blog_5de73d0b0101hwz8.html
try { Instrumentation inst=new Instrumentation(); inst.sendKeyDownUpSync(KeyEvent.KEYCODE_POWER); } catch (Exception e) { Log.e("tt","eeeeeeeeeeeeeeeee"); // TODO Auto-generated catch block e.printStackTrace(); }
模拟长按电源键:
Instrumentation inst=new Instrumentation(); KeyEvent k = new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_POWER); inst.sendKeySync(k); try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } k = new KeyEvent(KeyEvent.ACTION_UP,KeyEvent.KEYCODE_POWER); inst.sendKeySync(k);
触摸:
Instrumentation inst=new Instrumentation(); MotionEvent e = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN,10, 10, 0); inst.sendPointerSync(e); e = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, 10, 10, 0); inst.sendPointerSync(e);
参考文章:http://blog.163.com/fanning_7213/blog/static/24965052011312113638776/
http://blog.sina.com.cn/s/blog_68f262210102vc1b.html
http://blog.sina.com.cn/s/blog_5de73d0b0101hwz8.html
相关文章推荐
- 设计模式(2)--工厂模式
- tomcat安装与配置
- Ant打包时候报jre错误
- iOS-根据文本的长度确定label的宽高
- ubuntu_socket通信入门_sever.cpp/client.cpp_g++编译
- ASP网站项目编译
- 启动和关闭JBoss As 7.1.1脚本
- excel公式处理成绩表
- zTree控件加载权限信息的保存
- Unity学习笔记(4) --- Unity的界面排版: RectTransform
- H - Rescue hdu1242
- postgresql_fdw 跨数据库查询
- PyQt学习笔记01-Qt基本概念进阶篇
- 安全驾驶-双手开车(三十九)
- 表名在数据库中的存储大小写略解
- Java IO流之如何选择流对象总结
- MySqlDB基本操作程序一览
- Linux每日学习(十四)
- style,getComputedStyle,currentStyle,defaultView,getPropertyValue
- 仿微信联系人索引列表ListView