public class Win32Hook
{    [DllImport("kernel32")]
    public static extern int GetCurrentThreadId();    [DllImport( "user32", 
CharSet=CharSet.Auto,CallingConvention=CallingConvention.StdCall)]
    public static extern int  SetWindowsHookEx(
        HookType idHook,
        HOOKPROC lpfn,
        int hmod,
        int dwThreadId);    public enum HookType
    {
        WH_KEYBOARD = 2
    }
    
public delegate int HOOKPROC(int nCode, int wParam, int    lParam);    public void SetHook()
    {
        // set the keyboard hook
        SetWindowsHookEx(HookType.WH_KEYBOARD,
            new HOOKPROC(this.MyKeyboardProc),
            0,
            GetCurrentThreadId());
    }    public int MyKeyboardProc(int nCode, int wParam, int lParam)
    {
        //在这里放置你的处理代码        return 0;
    }
}
使用方法
可以在Form的构造函数里放入
Win32Hook hook = new Win32Hook();
hook.SetHook();

解决方案 »

  1.   

    yarshray(saga jion) :
    错了,您写的不是全局键盘钩子而是localhook!
      

  2.   

    http://www.vbcity.com/forums/topic.asp?tid=5733
    vb.net的
    SetWindowsHookEx、UnhookWindowsHookEx
      

  3.   

    http://expert.csdn.net/Expert/topic/1135/1135992.xml?temp=.1188776
      

  4.   

    在这里声明一下,希望楼主不要介意 yarshray(saga jion)兄在很多帖子中
    发言---很有热心---我所说赞扬的高手只举了班兄为例子,其实我对包括尼在内的诸位高手都是满怀敬意的。
      

  5.   

    to:hillwell(天子门生) 贴主问的是怎样做钩子!!!!!
      

  6.   

    不明白hillwell(天子门生)说的是什么意思?
      

  7.   

    转的:Global Hook Is Not Supported in .NET FrameworkYou cannot implement global hooks in Microsoft .NET Framework. To install a global hook, a hook must have a native dynamic-link library (DLL) export to inject itself in another process that requires a valid, consistent function to call into. This requires a DLL export, which .NET Framework does not support. Managed code has no concept of a consistent value for a function pointer because these function pointers are proxies that are built dynamically.
      

  8.   

    Win2K、NT下屏蔽Ctrl+Alt+Del的响应 这是一个系统级的调用,从普通的用户态根本没办法
    所以必须使用登陆http://www.csdn.net/magazine/download.shtm详细解说!