ReadyGo!技术成就梦想 >> .Net技术 >> XML&WebService >> c中键盘钩子的使用(转)

c中键盘钩子的使用(转)

ReadyGo!技术成就梦想 www.efish.cn efish 2007-10-25 10:14:40
public class win32hook
{

    
    public static extern int getcurrentthreadid();

    
    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();




相关文章
c中键盘钩子的使用(转) public class win32hook{ public static extern int getcurrentthreadid(); public sta..
c中键盘钩子的使用(转) public class win32hook{ public static extern int getcurrentthreadid(); public sta..
2秒记住本站域名

玩过泡泡龙吗?Readygo?Go! 再加上.Com.Cn的后缀,那就是大名小顶的ReadyGo.com.cn

分类导航
ReadyGo!技术成就梦想