Пример #1
0
 /// <summary>
 /// 設置鍵盤掛鉤。
 /// </summary>
 /// <returns></returns>
 virtual public bool Install()
 {
     if (!IsInstalled)
     {
         m_KbdHookProc = new HookProc(this.KeyboardHookProc);
         int threadId = WinKernel.GetCurrentThreadId();
         m_HookHandle = WinKernel.SetWindowsHookEx(WinApiConst.WH_KEYBOARD, m_KbdHookProc, IntPtr.Zero, threadId);
         return(m_HookHandle != 0);
     }
     return(true);
 }
Пример #2
0
        /// <summary>
        /// 設置鍵盤掛鉤。
        /// </summary>
        /// <returns></returns>
        public override bool Install()
        {
            if (!IsInstalled)
            {
                using (Process curProcess = Process.GetCurrentProcess())
                    using (ProcessModule curModule = curProcess.MainModule)
                    {
                        m_KbdHookProc = new HookProc(this.KeyboardHookProc);

                        m_HookHandle = WinKernel.SetWindowsHookEx(WinApiConst.WH_KEYBOARD_LL, m_KbdHookProc,
                                                                  WinKernel.GetModuleHandle(curModule.ModuleName), 0);
                    }
                return(m_HookHandle != 0);
            }
            return(true);
        }