2011-08-10 11 views
-1

私は、WM_KEYDOWNイベントを受け取ったときにLPARAMの値を調べています。しかし、私は最初の16ビットを調べてから次の8ビットを正しく調べていることがわかりません&これは、MSDNのLPARAMがWM_KEYDOWNのMSGのために編成されている方法について説明します:http://msdn.microsoft.com/en-us/library/ms646280(v=vs.85).aspxこのLPARAMは正しく分離されていますか?

は私の少し(?分割)正しい?:あなたが行くここ

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

です。

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

私はin your previous questionに答えとして、あなたは本当にdeclaring your own custom structureでなければなりません。それははるかに一貫性があり、エラーを起こしにくいです。これは、この特定の状況に対して単純に意味を持ち、言語の構造を最大限に活用します。ここでビット演算を行う必要はありません。

編集:つまり、Antonの解答です。

+0

なぜdownvote?あなたは 'KeyInfo.nRepeatCount'よりも'(lParam)&0xFFFF'を見るでしょうか? –

関連する問題