lapijn
asked on
systemwide
I made a simple program with a systemwide keyboardhook using SetWindowsHookEx with LowLevelKeyboardProc.
here's the code:
****************
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
BOOL fHandled = FALSE;
if (nCode == HC_ACTION)
{
KBDLLHOOKSTRUCT *pkbdllhook = (KBDLLHOOKSTRUCT *)lParam;
switch (pkbdllhook->vkCode)
{
case VK_F12:
CTraa_004Dlg* maind = (CTraa_004Dlg*)theApp.GetM ainWnd();
MessageBox(0,"ef","12",0);
fHandled = TRUE;
break;
}
}
return (fHandled ? TRUE : CallNextHookEx(ghhookKB, nCode, wParam, lParam));
}
*******************
now, my questions are:
1/I was told that something which is systemwide has to be in a dll, but it works, and it is an exe.
2/It works, but the MessageBox gets called twice (when I press F12) I don't understand why...
thanks
here's the code:
****************
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
BOOL fHandled = FALSE;
if (nCode == HC_ACTION)
{
KBDLLHOOKSTRUCT *pkbdllhook = (KBDLLHOOKSTRUCT *)lParam;
switch (pkbdllhook->vkCode)
{
case VK_F12:
CTraa_004Dlg* maind = (CTraa_004Dlg*)theApp.GetM
MessageBox(0,"ef","12",0);
fHandled = TRUE;
break;
}
}
return (fHandled ? TRUE : CallNextHookEx(ghhookKB, nCode, wParam, lParam));
}
*******************
now, my questions are:
1/I was told that something which is systemwide has to be in a dll, but it works, and it is an exe.
2/It works, but the MessageBox gets called twice (when I press F12) I don't understand why...
thanks
ASKER
thanks.
But how should I set WM_KEYDOWN ?? I tried to set it as a default parameter, but apparently this doesn't does the job...
But how should I set WM_KEYDOWN ?? I tried to set it as a default parameter, but apparently this doesn't does the job...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks. It works.
(However, I can only press the OK button after 5 seconds).
(However, I can only press the OK button after 5 seconds).
Never use MessageBox and any other interaction functions inside of hook function. For testing purposes use TRACE.
ASKER
ok.thanks.
2) It is called twice - first time for WM_KEYDOWN message, second time for WM_KEYUP message. Test wParam for this.