Android: 用Instrumentation类发送鼠标或按键事件

长平狐 发布于 2012/06/20 11:03
阅读 3K+
收藏 0

模拟鼠标MotionEvent.ACTION_DOWN:

new Thread () {
					public void run () {
						try {
			 		         Instrumentation inst=new Instrumentation();
			 		         inst.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(),
			 		        		 SystemClock.uptimeMillis(), 
			 		        		 MotionEvent.ACTION_DOWN, 240, 400, 0));
			 		         inst.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(),
			 		        		 SystemClock.uptimeMillis(), 
			 		        		 MotionEvent.ACTION_UP, 240, 400, 0)); 	
						} catch(Exception e) {
							Log.e("Exception when sendPointerSync", e.toString());
						}
					}
				}.start();
 


原文链接:http://blog.csdn.net/zmyde2010/article/details/6204596
加载中
返回顶部
顶部