示例#1
0
 /// <summary>
 /// Start the mouse hook.
 /// </summary>
 /// <returns>True if no exceptions.</returns>
 public static bool Enable()
 {
     if (Enabled == false)
     {
         try
         {
             using (Process curProcess = Process.GetCurrentProcess())
                 using (ProcessModule curModule = curProcess.MainModule)
                     hHook = Hooks.SetWindowsHookEx((int)Hooks.HookType.WH_MOUSE_LL, hookproc, Hooks.GetModuleHandle(curModule.ModuleName), 0);
             Enabled = true;
             return(true);
         }
         catch
         {
             Enabled = false;
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
示例#2
0
 /// <summary>
 /// Start the keyboard hook.
 /// </summary>
 /// <returns>True if no exceptions.</returns>
 public static bool Enable()
 {
     if (_enabled == false)
     {
         try
         {
             using (var curProcess = Process.GetCurrentProcess())
                 using (var curModule = curProcess.MainModule)
                     _hHook = Hooks.SetWindowsHookEx((int)Hooks.HookType.WhKeyboardLl, _hookproc, Hooks.GetModuleHandle(curModule.ModuleName), 0);
             _enabled = true;
             return(true);
         }
         catch
         {
             _enabled = false;
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }