AMOTION_EVENT_BUTTON_PRIMARY = 1 << 0, //左键 /** secondary */ AMOTION_EVENT_BUTTON_SECONDARY = 1 << 1, //右键 /** tertiary */ AMOTION_EVENT_BUTTON_TERTIARY = 1 << 2, //辅助按钮
1. 实现单击鼠标右键返回功能
实现单击鼠标右键返回功能
modified: frameworks/native/services/inputflinger/reader/mapper/accumulator/CursorButtonAccumulator.cpp
diff --git a/frameworks/native/services/inputflinger/reader/mapper/accumulator/CursorButtonAccumulator.cpp b/frameworks/native/services/inputflinger/reader/mapper/accumulator/CursorButtonAccumulator.cpp
index 168b0a7..197e178 100755
--- a/frameworks/native/services/inputflinger/reader/mapper/accumulator/CursorButtonAccumulator.cpp
+++ b/frameworks/native/services/inputflinger/reader/mapper/accumulator/CursorButtonAccumulator.cpp
@@ -107,7 +107,7 @@ uint32_t CursorButtonAccumulator::getButtonState() const {
if (mBtnRight) {
char targetProduct[PROPERTY_VALUE_MAX] = {0};
property_get("ro.target.product", targetProduct, "");
- if (strcmp(targetProduct, "box") == 0 || strcmp(targetProduct, "atv") == 0) {
+ if (strcmp(targetProduct, "box") == 0 || strcmp(targetProduct, "atv") == 0 || strcmp(targetProduct, "tablet") == 0) {
result |= AMOTION_EVENT_BUTTON_BACK;
} else {
result |= AMOTION_EVENT_BUTTON_SECONDARY;
2. 屏蔽鼠标右键滑动事件
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;
3. 添加鼠标右键Menu功能
3.1 定义menu
frameworks/native/include/android/input.h
/**
* Constants that identify buttons that are associated with motion events.
* Refer to the documentation on the MotionEvent class for descriptions of each button.
*/
enum {
/** primary */
AMOTION_EVENT_BUTTON_PRIMARY = 1 << 0,
/** secondary */
AMOTION_EVENT_BUTTON_SECONDARY = 1 << 1,
/** tertiary */
AMOTION_EVENT_BUTTON_TERTIARY = 1 << 2,
/** back */
AMOTION_EVENT_BUTTON_BACK = 1 << 3,
/** forward */
AMOTION_EVENT_BUTTON_FORWARD = 1 << 4,
AMOTION_EVENT_BUTTON_STYLUS_PRIMARY = 1 << 5,
AMOTION_EVENT_BUTTON_STYLUS_SECONDARY = 1 << 6,
AMTION_EVENT_BUTTON_MENU = 1 << 7, //add menu by jimmy
};
frameworks/native/services/inputflinger/reader/mapper/TouchCursorInputMapperCommon.h
static void synthesizeButtonKeys(InputReaderContext* context, int32_t action, nsecs_t when,
int32_t deviceId, uint32_t source, int32_t displayId,
uint32_t policyFlags, int32_t lastButtonState,
int32_t currentButtonState) {
synthesizeButtonKey(context, action, when, deviceId, source, displayId, policyFlags,
lastButtonState, currentButtonState, AMOTION_EVENT_BUTTON_BACK,
AKEYCODE_BACK);
synthesizeButtonKey(context, action, when, deviceId, source, displayId, policyFlags,
lastButtonState, currentButtonState, AMOTION_EVENT_BUTTON_FORWARD,
AKEYCODE_FORWARD);
synthesizeButtonKey(context, action, when, deviceId, source, displayId, policyFlags,
lastButtonState, currentButtonState, AMTION_EVENT_BUTTON_MENU, AKEYCODE_MENU);//add menu ++ by jimmy
}
3.2 实现鼠标右键 menu
framework/native/services/inputflinger/reader/mapper/accumulator/CursorButtonAccumulator.cpp
uint32_t CursorButtonAccumulator::getButtonState() const {
uint32_t result = 0;
if (mBtnLeft) {
result |= AMOTION_EVENT_BUTTON_PRIMARY;
}
if (mBtnOk) {
char mKeyMouseState[PROPERTY_VALUE_MAX] = {0};
property_get("sys.KeyMouse.mKeyMouseState", mKeyMouseState, "off");
if (strcmp(mKeyMouseState, "on") == 0) {
result |= AMOTION_EVENT_BUTTON_PRIMARY;
}
}
if (mBtnRight) {
char targetProduct[PROPERTY_VALUE_MAX] = {0};
property_get("ro.target.product", targetProduct, "");
if (strcmp(targetProduct, "box") == 0 || strcmp(targetProduct, "atv") == 0) {
result |= AMTION_EVENT_BUTTON_MENU; // add menu by jimmy
} else {
//result |= AMOTION_EVENT_BUTTON_SECONDARY;
result |= AMTION_EVENT_BUTTON_MENU; // add menu by jimmy
}
}
if (mBtnMiddle) {
result |= AMOTION_EVENT_BUTTON_TERTIARY;
}
if (mBtnBack || mBtnSide) {
result |= AMOTION_EVENT_BUTTON_BACK;
}
if (mBtnForward || mBtnExtra) {
result |= AMOTION_EVENT_BUTTON_FORWARD;
}
return result;
}
参考文献:
Android12 Framework屏蔽鼠标左/右键滑动事件-优快云博客
鼠标右键不能返回问题 - M-kobe - 博客园 (cnblogs.com)
activity支持鼠标 android 安卓鼠标按键设置_laokugonggao的技术博客_51CTO博客
rk3568 android11 鼠标右键点击无法返回_rk3568 鼠标右键后退_Haidern的博客-优快云博客
Android key键值 android 键值表_mob6454cc647bdb的技术博客_51CTO博客