Hi everyone!
I am using a dll to hook keyboard strokes for my application.
The hook works fine, but now i want to disable some keystrokes while my application is running.
So i did the following :
_declspec(dllexport) LRESULT CALLBACK KBHookProc(int Code, WPARAM wParam, LPARAM lParam)
{
if (Code < 0) return(CallNextHookEx(hhook, Code, wParam, lParam));
if (lParam & (1 << 31))
{
if(wParam==VK_F2)
{
keystrokes = 2;
keytime=GetTickCount();
return(CallNextHookEx(hhook, Code, wParam, lParam));
}
else if (wParam == VK_F3)
{
keystrokes = 3;
keytime=GetTickCount();
return(CallNextHookEx(hhook, Code, wParam, lParam));
}
else if (wParam == VK_F4)
{
keystrokes = 4;
keytime=GetTickCount();
return(CallNextHookEx(hhook, Code, wParam, lParam));
}
else if (wParam == VK_F5)
{
keystrokes = 5;
keytime=GetTickCount(); //I WANT TO BLOCK F5 so i do not return callnexthookex
return -1;
}
//... OTHER KEYS I WANT TO BE PROCESSED
//....
else
{
keystrokes = 0;
return(CallNextHookEx(hhook, Code, wParam, lParam));
}
}
return -1; // If i keep this line ALL keys are blocked
//return(CallNextHookEx(hhook, Code, wParam, lParam)); // if i keep this line all keystrokes pass including F5 i am trying to block.
}
So as you see on the comments above i try for example to block F5 keystroke by "breaking" the hook chain.
The last to lines as stated above, both produce unwanted effects.
Is there anyway i could sort this out? Has anyone done this before? I searched really thorougly through the net and couldn't find anything. Using another technique (such as other applications or registry tweaks) is not an option.
Thanks in advance!