У меня есть простой код, который проверяет значения (биты) переменной LPARAM (отправленной в основной WNDPROC) при получении WM_KEYDOWN.
Но я получаю несколько забавных значений int: В MSDN, http://msdn.microsoft.com/en-us/library/ms646280(v=vs.85).aspx, говорит, что последний бит (из LPARAM) всегда должен быть 0 для сообщения о нажатой клавише, но когда я вывожу значение LPARAM ВСЕГДА 1? Кроме того, код сканирования всегда изменяется между 5 (когда я нажимаю стрелку или клавишу Windows) или ноль для обычных букв и цифр - не должны ли они меняться в зависимости от нажатой клавиши?
Наконец, если я удерживаю клавишу 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");
}