我正在尝试获取扩展键状态
WNDPROC lpfnEditWndProc;
//edit - hwnd of edit control
lpfnEditWndProc = (WNDPROC) SetWindowLong(edit, GWL_WNDPROC, (DWORD) SubClassProc);
struct Bits {
WORD nRepeatCount: 16;
BYTE nScanCode : 8;
BYTE nExtended : 1;
BYTE nReserved : 4;
BYTE nContext : 1;
BYTE nPrevious : 1;
BYTE nTransition : 1;
};
union KeyInfo
{
LPARAM lParam;
Bits bits;
};
LRESULT CALLBACK SubClassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_CHAR:
{
KeyInfo v;
v.lParam = lParam;
printf("nExtended = %d\n", v.bits.nExtended);
}
break;
}
return CallWindowProc(lpfnEditWndProc, hwnd, msg, wParam, lParam);
}
nExtended 总是 == 0
我尝试以不同的方式获取信息,比如 (lParam << 24) & 1;
都一样 nExtended == 0
Win7 64 位,Visual Studio 2010
最佳答案
Because there is not necessarily a one-to-one correspondence between keys pressed and character messages generated, the information in the high-order word of the lParam parameter is generally not useful to applications. The information in the high-order word applies only to the most recent WM_KEYDOWN message that precedes the posting of the WM_CHAR message.
您必须处理 WM_KEYDOWN 和 WM_KEYUP 消息才能获得扩展 key 信息。
关于c++ - WM_CHAR lParam 扩展 key (24 位)始终为 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10671526/