IMS:键盘鼠标事件
android11-release
IMS:键盘鼠标接入判断
键盘鼠标接入EventHub
可查看IMS:EventHub 设备添加和InputDevice转化、IMS:键盘鼠标接入判断
- 鼠标名称:MI Mouse BT3.0
- 分配的DeviceId:11
- 分配的设备节点:/dev/input/event8
- classes=0x80000008、sources=0x00002002
- INPUT_DEVICE_CLASS_CURSOR:经 EventHub、InputDevice 处理后,添加 CursorInputMapper
CursorInputMapper事件处理
frameworks\native\services\inputflinger\reader\mapper\CursorInputMapper.cpp
- mEventHub->getEvents获取设备节点
/dev/input/event8
事件
/*
* A raw event as retrieved from the EventHub.
*/
struct RawEvent {
nsecs_t when;
int32_t deviceId;
int32_t type;
int32_t code;
int32_t value;
};
InputReader::processEventsForDeviceLocked
->InputDevice::process
->CursorInputMapper::process
鼠标按键事件
frameworks\native\services\inputflinger\reader\mapper\accumulator\CursorButtonAccumulator.cpp
external\kernel-headers\original\uapi\linux\input-event-codes.h
- 日志输出:鼠标左键
BTN_LEFT 0x110
、鼠标右键BTN_RIGHT 0x111
、鼠标中键BTN_MIDDLE 0x112
等
鼠标按键前后添加AKEY_EVENT_ACTION_DOWN、AKEY_EVENT_ACTION_UP事件
void CursorInputMapper::sync(nsecs_t when) {
int32_t lastButtonState = mButtonState;
int32_t currentButtonState = mCursorButtonAccumulator.getButtonState();
mButtonState = currentButtonState;
// ... ... ... ...
// Synthesize key down from buttons if needed.
synthesizeButtonKeys(getContext(), AKEY_EVENT_ACTION_DOWN, when, getDeviceId(), mSource,
displayId, policyFlags, lastButtonState, currentButtonState);
// ... ... ... ..
// Synthesize key up from buttons if needed.
synthesizeButtonKeys(getContext(), AKEY_EVENT_ACTION_UP, when, getDeviceId(), mSource,
displayId, policyFlags, lastButtonState, currentButtonState);
// ... ... ... ...
}
- synthesizeButtonKeys 只有在AMOTION_EVENT_BUTTON_BACK\AMOTION_EVENT_BUTTON_FORWARD(即
BTN_BACK 0x116\BTN_FORWARD 0x115
)添加
鼠标悬停、滑动事件
- 鼠标悬停 AMOTION_EVENT_ACTION_HOVER_MOVE:
motionEventAction == AMOTION_EVENT_ACTION_UP && (mSource == AINPUT_SOURCE_MOUS
- 鼠标滑动 AMOTION_EVENT_ACTION_SCROLL:
bool scrolled = vscroll != 0 || hscroll != 0;
CursorInputMapper最终添加NotifyMotionArgs
CursorInputMapper::sync
添加的NotifyMotionArgs,最总socket发送connection->inputPublisher.publishMotionEvent
( 除了BTN_BACK 0x116\BTN_FORWARD 0x115
)
-
connection->inputPublisher.publishMotionEvent
发送frameworks\native\libs\input\InputTransport.cpp