我在用键盘的线程钩子时也遇到点问题,现在改用全局钩子了。
帮你顶

解决方案 »

  1.   

    那些代码  他们都是写在添加的类里面的,而不是把全部代码都写在一个类中。你可以自己来整理一下的。刚开始的时候我也遇到了那些问题!
      

  2.   

    鼠标钩子:
    http://dev.csdn.net/develop/article/41/41301.shtm
    参考函数:
    那就用Hook了,参考如下的函数:
    //装置钩子的函数
    [DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
    public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);//卸下钩子的函数(已用C#语法修改过,可以直接用)
    [DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
    public static extern bool UnhookWindowsHookEx(int idHook);[DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
    public static extern int CallNextHookEx(int idHook, int nCode, Int32 wParam, IntPtr lParam);  [DllImport("user32")] 
    public static extern int GetKeyboardState(byte[] pbKeyState);public delegate int HookProc(int nCode, Int32 wParam, IntPtr lParam);