我有一些簡單的代碼,當收到WM_KEYDOWN時檢查LPARAM變量(發送到主WNDPROC)值(位)。檢查WM_KEYDOWN上的LPARAM - 不正確的值?
但我得到一些有趣的價值詮釋有:在MSDN,http://msdn.microsoft.com/en-us/library/ms646280(v=vs.85).aspx,它說(的LPARAM)最後一位應該永遠是0爲的keydown消息,但是當我輸出的LPARAM值它始終爲1?此外,掃描碼只能在5(當我按下箭頭或Windows鍵時)或0爲正常字母時改變 - 不應該根據按下的按鍵而改變嗎?
最後,如果我按住shift鍵一段時間,重複次數不應該增加嗎?當我這樣做時,重複計數保持爲零?
我的代碼檢查LPARAM值是錯誤的還是我的整個消息泵?
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_KEYDOWN:
{
outputLParam(lParam);
outputLParamDefault(lParam);
//printf("A: %d, %d, %d\n", lParam & 0x30, lParam & 0x31, lParam & 0x32);
//printf("\n");
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
void outputLParam(LPARAM lParam)
{
printf("Repeat Count : %d\n", (lParam >> 0x01) & ((1<<15)-1)); // print the value of the 1st 15 bits
printf("Scan Code : %d\n", (lParam >> 0x16) & ((1<<7)-1)); // print the value of the next 7 bits
printf("Extended Key : %d\n", lParam & 0x24); // print the value of the next bit
printf("Reserved : %d\n", (lParam >> 0x25) & ((1<<3)-1)); // print the value of the next 3 bits
printf("Context : %d\n", lParam & 0x29); // print the value of the next bit
printf("Prev Key State : %d\n", lParam & 0x30); // print the value of the next bit
printf("Transition Key State: %d\n", lParam & 0x31); // print the value of the next bit
}
void outputLParamDefault(LPARAM lParam)
{
printf("LPARAM: ");
for (int i=0x01, j=0; j<32; j++, i++)
{
printf("%d", lParam & i);
}
printf("\n");
}