我试图写一个键盘logging器,但是当我切换一种语言时,我遇到了问题。
我的键盘上有希伯来文和英文。
它分开表示希伯来语和英语,问题是如果我改变语言(ALT + shift),所以它仍然是第一语言。
码:
LRESULT __declspec(dllexport)__stdcall CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) { char ch; if (((DWORD)lParam & 0x40000000) && (HC_ACTION == nCode)) { if ((wParam == VK_SPACE) || (wParam == VK_RETURN) || (wParam >= 0x2f) && (wParam <= 0x100)) { std::string toPrint = "nCode = " + std::to_string(nCode); std::string toPrint2 = "wParam = " + std::to_string(wParam); std::string toPrint3 = "wParam = " + std::to_string(lParam); OutputDebugStringA(toPrint.c_str()); OutputDebugStringA(toPrint2.c_str()); OutputDebugStringA(toPrint3.c_str()); f1 = fopen("c:\\a\\log.txt", "a+"); if (wParam == VK_RETURN) { ch = '\n'; fwrite(&ch, 1, 1, f1); } else { BYTE ks[256]; GetKeyboardState(ks); WORD w; UINT scan; scan = 0; ToAscii(wParam, scan, ks, &w, 0); ch = char(w); fwrite(&ch, 1, 1, f1); } fclose(f1); } }
我看到nCode,wParam和lParam参数在两种语言中具有相同的值。
有任何想法吗?
谢谢!
我想你会想要处理WM_INPUTLANGCHANGEREQUEST消息。 我假设你会一直想接受语言的变化。