hi
input命令扩展提示部分
generic_x86_64:/ # input -h
Error: Unknown command: -h
Usage: input [<source>] <command> [<arg>...]
The sources are:
dpad
keyboard
mouse
touchpad
gamepad
touchnavigation
joystick
touchscreen
stylus
trackball
The commands and default sources are:
text <string> (Default: touchscreen)
keyevent [--longpress] <key code number or name> ... (Default: keyboard)
tap <x> <y> (Default: touchscreen)
mutiple-tap pointId <x> <y> .....(Default: touchscreen)
mutiple-touch action pointId <x> <y> ...... (action should be one of down,move,up;Default: touchscreen)
swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)
draganddrop <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)
press (Default: trackball)
roll <dx> <dy> (Default: trackball)
input帮助文案中额外添加了2个命令: mutiple-tap 和 mutiple-touch
mutiple-tap
mutiple-tap pointId …(Default: touchscreen)
代表多个手指的点击事件,其实就是motionevent有down和up两个事件成对,即类似click,有一个按下和抬起
使用规则参数多了一个pointId代表手指,一般从0开始。
mutiple-tap 操作如下:
日志打印如下:
dispatchTouchEvent ev = MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=200.0, y[0]=200.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=14469497, downTime=14469497, deviceId=0, source=0x1002 }
dispatchTouchEvent ev = MotionEvent { action=ACTION_POINTER_DOWN(1), actionButton=0, id[0]=0, x[0]=200.0, y[0]=200.0, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=210.0, y[1]=210.0, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=0, eventTime=14469498, downTime=14469498, deviceId=0, source=0x1002 }
dispatchTouchEvent ev = MotionEvent { action=ACTION_POINTER_UP(0), actionButton=0, id[0]=0, x[0]=200.0, y[0]=200.0, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=210.0, y[1]=210.0, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=0, eventTime=14469498, downTime=14469498, deviceId=0, source=0x1002 }
dispatchTouchEvent ev = MotionEvent { action=ACTION_UP, actionButton=0, id[0]=1, x[0]=210.0, y[0]=210.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=14469499, downTime=14469499, deviceId=0, source=0x1002 }
看可以看到app接受到的多指事件也是正常的
第一个手指 down
– 》第二个手指 ACTION_POINTER_DOWN(1)
–》第一个手指抬起ACTION_POINTER_UP(0)
–》第二个手指抬起ACTION_UP
mutiple-touch
mutiple-touch action pointId … (action should be one of down,move,up;Default: touchscreen)
仅仅代表触摸事件,它没有和tap一样有一个down和up成对,它只有一个action,而且这个action还是需要用户指定的,是down,move,up中的一个,一般都需要严格按照规则:
事件先有down,再有move,最后有up的顺序。
使用规则参数相比上面tap额外多了一个action,它来指定当前触摸具体action类型
命令如下:
input mutiple-touch down 0 200 200 1 210 210
按下后其实一直是down状态,会等待up
输入down:
generic_x86_64:/ # input mutiple-touch down 0 200 200 1 210 210
输入move:
generic_x86_64:/ # input mutiple-touch move 0 220 220 1 230 230
输入up:
generic_x86_64:/ # input mutiple-touch up 0 220 220 1 230 230
相关日志:
dispatchTouchEvent ev = MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=200.0, y[0]=200.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=19712743, downTime=19712743, deviceId=0, source=0x1002 }
dispatchTouchEvent ev = MotionEvent { action=ACTION_POINTER_DOWN(1), actionButton=0, id[0]=0, x[0]=200.0, y[0]=200.0, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=210.0, y[1]=210.0, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=0, eventTime=19712745, downTime=19712745, deviceId=0, source=0x1002 }
dispatchTouchEvent ev = MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=220.0, y[0]=220.0, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=230.0, y[1]=230.0, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=0, eventTime=19720967, downTime=19720967, deviceId=0, source=0x1002 }
dispatchTouchEvent ev = MotionEvent { action=ACTION_POINTER_UP(0), actionButton=0, id[0]=0, x[0]=220.0, y[0]=220.0, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=230.0, y[1]=230.0, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=0, eventTime=19724517, downTime=19724517, deviceId=0, source=0x1002 }
dispatchTouchEvent ev = MotionEvent { action=ACTION_UP, actionButton=0, id[0]=1, x[0]=230.0, y[0]=230.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=19724518, downTime=19724518, deviceId=0, source=0x1002 }
日志也展示多指的Down --》 Move—》UP
本文章对应视频手把手教你学framework:
七件套专题:
点击这里 https://mp.weixin.qq.com/s/Qv8zjgQ0CkalKmvi8tMGaw
hal+perfetto+surfaceflinger
https://mp.weixin.qq.com/s/LbVLnu1udqExHVKxd74ILg
私聊作者+v(androidframework007)
视频:https://www.bilibili.com/video/BV1wc41117L4/