Hi All,
I am working on Application Keyboard hook in C#.Net.
I need to do some funcationlity when user presses "Esc" key in my application.
Iam able to capture "Esc" key in the application, but hookprocedure is calling two times when ever i press "Esc" button and in turns my functionality is calling two times.
Iam sure iam pressing "Esc" key only one time.
Please help me in this.
following is code snippet.
hook procedure
public static int KeyHookProc(int nCode, IntPtr wParam, IntPtr lParam)
{
//MouseHookStruct MyMouseHookStruct = (MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(MouseHookStruct));
if (nCode < 0)
{
}
else
{
if (wParam.ToInt64() == 27)
{
Form1 obj = new Form1();
obj.myfunction();
}
else
{
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
}
return 0;
}
Hook Initialization:
KeyHookProcedure = new HookProc(Form1.KeyHookProc);
hHook = SetWindowsHookEx(WH_KEYBOARD,
KeyHookProcedure,
(IntPtr)0,
AppDomain.GetCurrentThreadId());
Thanks and Regards,
Veeresh.
Loading
veeresh veereshPosted May 13, 2010, 4:29 AM
Jaish MathewsPosted May 12, 2010, 1:12 PM
Hi,
I don't know your exact task.But just asking that for handling ESC key why can't you use Key_Down event handler of the Form?