如何在inputreader中拦截相应的virtual key
首先看哪里把virtual key往上报
发现InputReader.cpp里
void TouchInputMapper::dispatchVirtualKey(nsecs_t when, uint32_t policyFlags,
int32_t keyEventAction, int32_t keyEventFlags) {
int32_t keyCode = mCurrentVirtualKey.keyCode;
int32_t scanCode = mCurrentVirtualKey.scanCode;
nsecs_t downTime = mCurrentVirtualKey.downTime;
int32_t metaState = mContext->getGlobalMetaState();
policyFlags |= POLICY_FLAG_VIRTUAL;
ALOGE("matt-dispatchVirtualKey ");
FILE* keyfile= NULL;
char buff[256];
char buff1[256];
memset(buff,0,255);
memset(buff1,0,255);
keyfile=fopen("/data/key.txt" ,"r");//这个txt文件里写了一些字符串比如home,back,menu
if(keyfile==NULL)
ALOGE("matt-fopen failure ");
while(fscanf(keyfile,"%s",buff)!=-1)//按行读取
{
strcat(buff1,buff);//组合成一个字符串
memset(buff,0,255);
}
fclose (keyfile);
NotifyKeyArgs args(when, getDeviceId(), AINPUT_SOURCE_KEYBOARD, policyFlags,
keyEventAction, keyEventFlags, keyCode, scanCode, metaState, downTime);
ALOGE("matt-run to getevent====%d",keyCode);
if(strspn(buff1,"home")!=0)//看组合出来的字符串里是否有home
{
if ( keyCode!= 3) //home的keycode是3
getListener()->notifyKey(&args);
}
if(strspn(buff1,"back")!=0)
{
if ( keyCode!= 4)
getListener()->notifyKey(&args);
}
if(strspn(buff1,"menu")!=0)
{
if ( keyCode!= 82)
getListener()->notifyKey(&args);
}
}