2011-08-10 3 views
-1

WM_KEYDOWN 이벤트를받을 때 LPARAM의 값을 검사합니다. 그러나 나는 정확하게 다음 16 비트를 검사하고 다음 8 비트 &을 검사하고 있는지 확신 할 수 없다.이 LPARAM이 올바르게 분리되어 있습니까?

http://msdn.microsoft.com/en-us/library/ms646280(v=vs.85).aspx 내 비트 (분할?)인가 올바른? 여기

void outputLParam(LPARAM lParam) 
{ 
    printf("Repeat Count  : %d\n", (lParam) & ((1L<<16)-1));   // print the value of the 1st 16 bits 
    printf("Scan Code   : %d\n", (lParam >> 0x16) & ((1L<<8)-1)); // print the value of the next 8 bits 
    printf("Extended Key  : %d\n", lParam & 0x24);     // print the value of the next bit 
    printf("Reserved   : %d\n", (lParam >> 0x25) & ((1L<<4)-1)); // print the value of the next 4 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 
} 
+0

이것은 정말로 [이전 질문] (http://stackoverflow.com/questions/6993957/inspecting-the-lparam-on-wm-keydown-incorrect-values)의 후속 조치/계속 사항이었을 것입니다. – Deanna

답변

2

당신이가는 : MSDN이 LPARAM은 WM_KEYDOWN의 MSG에 대한 구성되어 방법에 대해 설명이다. 내가 in your previous question 대답으로

void outputLParam(LPARAM lParam) 
{ 
    printf("Repeat Count  : %d\n", (lParam) & 0xFFFF);  // print the value of the 1st 16 bits 
    printf("Scan Code   : %d\n", (lParam >> 16) & 0xFF); // print the value of the next 8 bits 
    printf("Extended Key  : %d\n", (lParam >> 24) & 0x1); // print the value of the next bit 
    printf("Reserved   : %d\n", (lParam >> 25) & 0xF)); // print the value of the next 4 bits 
    printf("Context    : %d\n", (lParam >> 29) & 0x1); // print the value of the next bit 
    printf("Prev Key State  : %d\n", (lParam >> 30) & 0x1); // print the value of the next bit 
    printf("Transition Key State: %d\n", (lParam >> 31) & 0x1); // print the value of the next bit 
} 
0

, 당신은 정말 declaring your own custom structure해야한다. 훨씬 일관성 있고 오류가 발생하기 쉽습니다. 이 특정 상황에 대해 더 이해하기 쉽고 언어 구성을 최대한 활용합니다. 여기서 비트 연산을 수행 할 필요가 없습니다.

편집 : 즉, Anton의 솔루션 입니다.

+0

왜 downvote? 'KeyInfo.nRepeatCount'보다'(lParam) & 0xFFFF'를 보시겠습니까? –

관련 문제