• [Android Input系统学习]从mouse事件再看input分发


    Android手机连接蓝牙鼠标后,屏幕上可以显示鼠标图标,在/dev/input里可以看到相应的设备,滑动和点击鼠标,getevent命令可以看到input数据。

    但是,我们较为熟悉的事件接收方法View#onTouchEvent里并没有调进去,在onTouchEvent里添加log,在点击的时候会有输出,但是滑动时没有输出,mouse设备的滑动难道不一样?

    较为直观的分析方法是打开InputDispatcher里的log开关,可以看到,滑动的时候,还是会走到notifyMotion方法,我们还可以抓取systrace来查看方法调用流程。

    从log里可以看到,滑动时会有action为7的事件,

    查看MotionEvent.java里的定义

    264    /**
    265     * Constant for {@link #getActionMasked}: A change happened but the pointer
    266     * is not down (unlike {@link #ACTION_MOVE}).  The motion contains the most
    267     * recent point, as well as any intermediate points since the last
    268     * hover move event.
    269     * 

    270 * This action is always delivered to the window or view under the pointer. 271 *

    272 * This action is not a touch event so it is delivered to 273 * {@link View#onGenericMotionEvent(MotionEvent)} rather than 274 * {@link View#onTouchEvent(MotionEvent)}. 275 *

    276 */ 277 public static final int ACTION_HOVER_MOVE = 7;

     * This action is not a touch event so it is delivered to * {@link View#onGenericMotionEvent(MotionEvent)} rather than * {@link View#onTouchEvent(MotionEvent)}.

    使用onGenericMotionEvent(MotionEvent) 方法,就可以获取到mouse的滑动事件了。

    可以看出,mouse设备的事件分发流程和屏幕touch事件的流程是一样的,只是处理细节不一样。

    InputReader线程调用InputDispatcher的notifyMotion方法,然后把事件放入到InBound队列中,

    LoopOnce被唤醒,开始后面的处理,调用DiapatchMotionLock等方法。

    通过systrace查看input的相关调用顺序还是比较清楚的。

  • 相关阅读:
    EBS R12.2.0升级到R12.2.6
    logrotate command in Linux
    计算机毕业设计springboot+vue基本微信小程序的云宠物小程序-宠物领养
    B46 - STM32太阳能充电智能心率监测骑行仪
    《发现的乐趣》作者费曼(读书笔记)
    查找算法.
    [Linux] [rpm -qa][|grep]查询是否安装了软件包
    19.在springboot中集成dubbo(zookeeper)
    JMeter入门教程(16)——非GUI运行
    js设计模式
  • 原文地址:https://blog.csdn.net/aaajj/article/details/126795195