/*******************************/
DWORD PBT_IntrThread(PVOID pArg)
{
DWORD ret;
//PBT_InitializeAddresses();
//PBT_EnableInterrupt();
// gPwrButtonIntrEvent[0] = CreateEvent(NULL, FALSE, FALSE, NULL);
// gPwrButtonIntrEvent[1] = CreateEvent(NULL, FALSE, FALSE, NULL);
// gPwrButtonIntrEvent[2] = CreateEvent(NULL, FALSE, FALSE, NULL);
// gPwrButtonIntrEvent[3] = CreateEvent(NULL, FALSE, FALSE, NULL);
gKeyWaitEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
//多个中断关联到一个事件上
if (!(InterruptInitialize(g_Key1SysIntr, gKeyWaitEvent, 0, 0)))
{
RETAILMSG(1, (TEXT("ERROR: PwrButton: Interrupt initialize failed.\r\n")));
CloseHandle(gKeyWaitEvent);
return 0;
}
if (!(InterruptInitialize(g_Key2SysIntr, gKeyWaitEvent, 0, 0)))
{
RETAILMSG(1, (TEXT("ERROR: PwrButton: Interrupt initialize failed.\r\n")));
CloseHandle(gKeyWaitEvent);
return 0;
}
if (!(InterruptInitialize(g_Key3SysIntr, gKeyWaitEvent, 0, 0)))
{
RETAILMSG(1, (TEXT("ERROR: PwrButton: Interrupt initialize failed.\r\n")));
CloseHandle(gKeyWaitEvent);
return 0;
}
if (!(InterruptInitialize(g_Key4SysIntr, gKeyWaitEvent, 0, 0)))
{
RETAILMSG(1, (TEXT("ERROR: PwrButton: Interrupt initialize failed.\r\n")));
CloseHandle(gKeyWaitEvent);
return 0;
}
while (1)
{
ret = WaitForSingleObject(gKeyWaitEvent, INFINITE);
//ret = WaitForMultipleObjects(gPwrButtonIntrEvent, INFINITE);
//ret = WaitForMultipleObjects(4,gPwrButtonIntrEvent,FALSE,INFINITE);
if((ret==WAIT_OBJECT_0)&&(g_bKillIST==FALSE ))
{
switch(PBT_IsPushed())
{
case 1: //按键1
//if(PBT_IsPushed()==1)
Sleep(20);
if(PBT_IsPushed()==1)
{
SetEvent(gReadKeyEvent[0]);
RETAILMSG(1, (TEXT("The button is Down!!!!!!!LTH~~~~~\r\n")));
}
InterruptDone(g_Key1SysIntr);
RETAILMSG(1, (TEXT("The Eint0 is Done!!!!!!!LTH~~~~~\r\n")));
break;
case 2:
//if(PBT_IsPushed()==2)
{
Sleep(20);
if(PBT_IsPushed()==2)
{
SetEvent(gReadKeyEvent[1]);
}
}
InterruptDone(g_Key2SysIntr);
RETAILMSG(1, (TEXT("The Eint1 is Done!!!!!!!LTH~~~~~\r\n")));
break;
case 3:
//if(PBT_IsPushed()==4)
{
Sleep(20);
if(PBT_IsPushed()==3)
{
SetEvent(gReadKeyEvent[2]);
//RETAILMSG(1, (TEXT("The button is Down!!!!!!!LTH~~~~~\r\n")));
}
}
InterruptDone(g_Key3SysIntr);
RETAILMSG(1, (TEXT("The Eint2 is Done!!!!!!!LTH~~~~~\r\n")));
break;
case 4:
//if(PBT_IsPushed()==8)
{
Sleep(20);
if(PBT_IsPushed()==4)
{
SetEvent(gReadKeyEvent[3]);
//RETAILMSG(1, (TEXT("The button is Down!!!!!!!LTH~~~~~\r\n")));
}
}
InterruptDone(g_Key4SysIntr);
RETAILMSG(1, (TEXT("The Eint4 is Done!!!!!!!LTH~~~~~\r\n")));
break;
default:
//CloseHandle(gPwrButtonIntrEvent[0]);
//CloseHandle(gPwrButtonIntrEvent[1]);
//CloseHandle(gPwrButtonIntrEvent[2]);
//CloseHandle(gPwrButtonIntrEvent[3]);
break;
}
}
else {
CloseHandle(gKeyWaitEvent);
return 0;
}
}
return 1;
}
}
我把多个中断关联到一个事件上,刚开始4个按键都能用,按几下有的就不能用了,最后甚至都不能用?为什么啊?是不是哪儿没有释放?