![](https://csdnimg.cn/release/download_crawler_static/9352285/bg3.jpg)
(scancode < RawInputEvent.BTN_FIRST ||
scancode >
RawInputEvent.BTN_LAST)) {
boolean down;
if (ev.value != 0) {
down = true;
di.mKeyDownTime = curTime;
} else {
down = false;
}
int keycode = rotateKeyCodeLocked(ev.keycode);
addLocked(di, curTimeNano, ev.flags,
RawInputEvent.CLASS_KEYBOARD,
newKeyEvent(di, di.mKeyDownTime,
curTime, down,
keycode, 0, scancode,
((ev.flags &
WindowManagerPolicy.FLAG_WOKE_HERE) != 0)
?
KeyEvent.FLAG_WOKE_HERE : 0));
}
处理键盘事件,并将该事件加入事件队列。
7.2 硬件调用
文件:frameworks/base/services/jni/com_android_server_KeyInputQueue.cpp
int register_android_server_KeyInputQueue(JNIEnv* env)
{
...
jclass inputEvent = env->FindClass("android/view/RawInputEvent");
gInputOffsets.mDeviceId
= env->GetFieldID(inputEvent, "deviceId", "I");
gInputOffsets.mType
= env->GetFieldID(inputEvent, "type", "I");
gInputOffsets.mScancode
= env->GetFieldID(inputEvent, "scancode", "I");
gInputOffsets.mKeycode
= env->GetFieldID(inputEvent, "keycode", "I");
gInputOffsets.mFlags
= env->GetFieldID(inputEvent, "flags", "I");
gInputOffsets.mValue
= env->GetFieldID(inputEvent, "value", "I");
gInputOffsets.mWhen