看看这个图片,有人用脚开飞机,用几个踏板去控制,在游戏中,开飞机的操作比较简单,上升,下降,加减油门,方向左,方向右。
android设备中,使用模拟点击就可以实现这个功能,在操作踏板的时候发送对应的touch事件,具体可以参考frameworks/base/cmds/input/src/com/android/commands/input/Input.java
209 private void sendTap(int inputSource, float x, float y) {
210 long now = SystemClock.uptimeMillis();
211 injectMotionEvent(inputSource, MotionEvent.ACTION_DOWN, now, x, y, 1.0f);
212 injectMotionEvent(inputSource, MotionEvent.ACTION_UP, now, x, y, 0.0f);
213 }
298 private void injectMotionEvent(int inputSource, int action, long when, float x, float y, float pressure) {
299 final float DEFAULT_SIZE = 1.0f;
300 final int DEFAULT_META_STATE = 0;
301 final float DEFAULT_PRECISION_X = 1.0f;
302 final float DEFAULT_PRECISION_Y = 1.0f;
303 final int DEFAULT_EDGE_FLAGS = 0;
304 MotionEvent event = MotionEvent.obtain(when, when, action, x, y, pressure, DEFAULT_SIZE,
305 DEFAULT_META_STATE, DEFAULT_PRECISION_X, DEFAULT_PRECISION_Y,
306 getInputDeviceId(inputSource), DEFAULT_EDGE_FLAGS);
307 event.setSource(inputSource);
308 Log.i(TAG, "injectMotionEvent: " + event);
309 InputManager.getInstance().injectInputEvent(event,
310 InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
311 }