遥控器实现蓝牙鼠标滑动总结
类别
需求
索引类别
外设
需求描述
海外客户需要用到浏览器, 浏览器没有焦点滑动功能,所以这就需要用到遥控器模拟鼠标滑动功能.
当前解决方案描述
目前蓝牙遥控器已经把遥控器模拟成了外设鼠标,但是缺少滑动的功能.
所以目前的解决方案就是将对应模拟一个滑动的事件出来(当鼠标移动到顶(底)端并且还有对应的Y轴移动时,即可模拟一个滑动的事件)
代码关联
frameworks/native/services/inputflinger/InputReader.cpp
@@ -2851,6 +2850,24 @@ void CursorInputMapper::sync(nsecs_t when) {
/*
@deltaY 代表对应鼠标Y轴有移动
@scrolled 代表滑动事件是否有触发
@vscroll 代表滑动的速度
*/
float x,y;
//蓝牙模拟鼠标滚动功能
if (deltaY != 0) {
if (mPointerController != NULL) {
//获取鼠标的x y 轴位置
mPointerController->getPosition(&x, &y);
//判断鼠标是否到达顶端(底部),并且有相对应的Y轴移动
if (y <= 5 && deltaY < 0) {
scrolled = true;
vscroll = 3;
} else if(y >= 1070 && deltaY > 0) {
scrolled = true;
vscroll = -3;
}
}
}
//触发滑动事件
mWheelYVelocityControl.move(when, NULL, &vscroll);
mWheelXVelocityControl.move(when, &hscroll, NULL);
mPointerVelocityControl.move(when, &deltaX, &deltaY);
知识拓展
外接设备事件处理:InputReader.cpp 在这里会接收鼠标,键盘,触摸屏, 游戏杆,External stylus-like devices.等
参考资料: https://blog.csdn.net/chenweiaiyanyan/article/details/72919272
https://www.jianshu.com/p/34f5c7d55337
改进建议
目前这个还有个缺点,就是当接入外设鼠标时,指针移动到顶端(底端)时,也会触发鼠标的滑动事件.
解决方案:需要蓝牙遥控器切换鼠标模式时,有对应的键码值发出,在 if (deltaY != 0) 添加一个键码接收.这样可以规避此类问题.
工作记录。。。。。