Android12 Framework屏蔽鼠标左/右键滑动事件

支持鼠标的Android设备,左键和右键都能拖动空间或者是都响应系统手势。现在需求是想屏蔽掉鼠标右键的滑动事件,仅响应鼠标左键滑动。

要修改该问题需要了解以下几个常量。

AMOTION_EVENT_BUTTON_PRIMARY 左键

AMOTION_EVENT_BUTTON_SECONDARY 右键

AMOTION_EVENT_BUTTON_TERTIARY 辅助按钮

具体改动如下:

diff --git a/services/inputflinger/reader/mapper/CursorInputMapper.cpp b/services/inputflinger/reader/mapper/CursorInputMapper.cpp
index edf4573218..7b29de98be 100644
--- a/services/inputflinger/reader/mapper/CursorInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/CursorInputMapper.cpp
@@ -417,7 +417,8 @@ void CursorInputMapper::sync(nsecs_t when, nsecs_t readTime) {
                          mSource, displayId, policyFlags, lastButtonState, currentButtonState);
 
     // Send motion event.
-    if (downChanged || moved || scrolled || buttonsChanged) {
+    if (downChanged || (moved && mCursorButtonAccumulator.getButtonState() != AMOTION_EVENT_BUTTON_SECONDARY) 
+        || scrolled || buttonsChanged) {
         int32_t metaState = getContext()->getGlobalMetaState();
         int32_t buttonState = lastButtonState;
         int32_t motionEventAction;

屏蔽右键的move事件。

猜你喜欢

转载自blog.csdn.net/guanmingyuangmy/article/details/132407109
今日推荐