Beispiel #1
0
            public override bool Install(Delegates.ProcessKeyHandle clientMethod)
            {
                try
                {
                    //客户端传入的委托,即截获消息之后,对消息的过滤和处理的方法
                    this.clientMethod = clientMethod;

                    // 安装键盘钩子
                    if (hHookId == 0)
                    {
                        keyBoardHookProcedure = GetHookProc;

                        hookWindowPtr = WinApi.Win32Api.Kernel32Api.GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName);

                        hHookId = WinApi.Win32Api.User32Api.SetWindowsHookEx(
                            (int)Model.Enums.KeyHookType.WH_KEYBOARD_LL,//调用系统方法安装钩子,第一个参数标识钩子的类型13为全局钩子
                            keyBoardHookProcedure,
                            hookWindowPtr,
                            0);

                        //如果设置钩子失败.
                        if (hHookId == 0)
                        {
                            UnInstall();
                        }
                    }
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
Beispiel #2
0
            public override bool Install(Delegates.ProcessKeyHandle clientMethod)
            {
                try
                {
                    this.clientMethod = clientMethod;

                    // 安装键盘钩子
                    if (hHookId == 0)
                    {
                        keyBoardHookProcedure = GetHookProc;

                        hookWindowPtr = WinApi.Win32Api.Kernel32Api.GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName);

                        hHookId = WinApi.Win32Api.User32Api.SetWindowsHookEx(
                            (int)Help.Model.Enums.KeyHookType.WH_KEYBOARD,
                            keyBoardHookProcedure,
                            IntPtr.Zero,
                            WinApi.Win32Api.Kernel32Api.GetCurrentThreadId()
                            );

                        //如果设置钩子失败.
                        if (hHookId == 0)
                        {
                            UnInstall();
                        }
                    }
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
Beispiel #3
0
 /// <summary>
 /// 安装钩子
 /// </summary>
 /// <param name="clientMethod"></param>
 /// <returns></returns>
 public abstract bool Install(Delegates.ProcessKeyHandle clientMethod);