检查WM_KEYDOWN上的LPARAM -不正确的值
Inspecting the LPARAM on WM_KEYDOWN - incorrect values?
我有一些简单的代码,检查LPARAM变量(发送到主WNDPROC)值(位)当WM_KEYDOWN被接收。
但是我在那里得到了一些有趣的值:在MSDN中,http://msdn.microsoft.com/en-us/library/ms646280(v=vs.85).aspx,它说最后一位(LPARAM)应该始终为按键消息为0,但当我输出LPARAM值时它总是1?此外,扫描码只会在5(当我按下箭头或窗口键时)或零(正常字母&数字——它们不应该根据按下的键而变化吗?
最后,如果我按住shift键一段时间,重复计数不应该上升吗?当我这样做的时候,重复计数一直是0吗?
我检查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, %dn", 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 : %dn", (lParam >> 0x01) & ((1<<15)-1)); // print the value of the 1st 15 bits
printf("Scan Code : %dn", (lParam >> 0x16) & ((1<<7)-1)); // print the value of the next 7 bits
printf("Extended Key : %dn", lParam & 0x24); // print the value of the next bit
printf("Reserved : %dn", (lParam >> 0x25) & ((1<<3)-1)); // print the value of the next 3 bits
printf("Context : %dn", lParam & 0x29); // print the value of the next bit
printf("Prev Key State : %dn", lParam & 0x30); // print the value of the next bit
printf("Transition Key State: %dn", 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");
}
您检查位的代码是错误的,和注释中声明的bitgroups是错误的。
。文档中说低16位是重复计数。
通过
得到(lParam >> 0) & ((1L << 16) - 1)
在你的代码使用的"system"中。
相反,您的代码有不正确的表达式(lParam >> 0x01) & ((1<<15)-1))
。
扫描码是接下来的8位,而不是7位。
干杯,hth。
所有的掩码计数都是错误的,重复计数偏移量是错误的。重复计数从第0位开始(而不是第1位),因此不需要移位,然后您的掩码会错过顶部位。
我刚才回答的一个问题与你的情况有关。创建一个自定义的结构,而不是创建一个混乱的位移位
相关文章:
- 使用2个键的cpp-stl::优先级队列排序不正确
- 正弦级数方程计算不正确
- 我试图制作一个程序,要求用户输入问题和答案,但程序循环不正确
- 密码登录程序将永远循环并显示不正确的结果
- 在C++中返回不正确的楼层函数值
- 形状对象的旋转和缩放不正确C++
- C++ 读取文件读取文件不正确
- 关于类的 Python 文档 - 对C++的引用不正确
- 特征 LLT 模块给出不正确的结果?
- glibcxx STL 在实现 std::valarray::sum() 时是否不正确?
- 如果语句逻辑不正确
- 来自逆 vp 矩阵和相机位置的光线方向不正确
- 不正确的操作数类型 MSVC
- 数组填充了不正确的值
- 我是否不正确地集中了这些字符数组?
- 为什么除非我使用 cout,否则我的值不正确?
- 计算幂级数的数学结果不正确
- 为什么 sizeof 在 C++ 中给出不正确的字节数?
- atoi() 在应用于大型命令行参数时会产生不正确的值
- 检查WM_KEYDOWN上的LPARAM -不正确的值