Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all . i am trying to implement keyboard hook ,it works however it repeats entered char for eg. if i enter hello it gives
HHHHHHHHHHHHHHHHHHHHHEEEEEEEEEEEEEEEEEEEEELLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLOOOOOOOOOOOOOOOOOOOOO

can any one help me here ?

i am using windows server 2008 r2 64 bit standard edition , with vs 2005 professional.

LRESULT   __declspec(dllexport)__stdcall  CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
	ofstream fout;
	fout.open("c:\\viv.txt",ios::app);

	static BOOL flag = FALSE ;
	static BYTE key ;

	if ( nCode < 0 )
		return CallNextHookEx ( hkb, nCode, wParam, lParam ) ;

	if ( ( nCode == HC_ACTION ) && (  (((DWORD)lParam & 0x80000000) == 0 ) && (((DWORD)lParam & 0x40000000 ) == 0 ) ))
	{
		if ((wParam==VK_SPACE)||(wParam==VK_RETURN)||((wParam>=0x2f ) &&(wParam<=0x100))) 
		{
			if(wParam != VK_RETURN)
			{
				key = (BYTE)wParam;
				fout<<key;
			}
		}
	}
		
	fout.close();

   return CallNextHookEx(hkb, nCode, wParam, lParam);
}
Posted

You must use KeyUp or KeyDown to log the keys. Check this sample in VB.Net
http://sim0n.wordpress.com/2009/03/28/vbnet-keyboard-hook-class/[^]
 
Share this answer
 
did not work , any way thanks for reply

switch(wParam)
{
case WM_KEYDOWN:
    keystat = 1;
    break;
case WM_KEYUP:
    if(keystat == 1)
    {
        keystat = 2;
        key = (BYTE)wParam;
        fout<<key;
    }
    break;
default:
    if(keystat == 2)
    {
        keystat = 0;
        key = (BYTE)wParam;
        fout<<key;
    }
}
 
Share this answer
 

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