Exemple #1
0
 private static void InstallHook()
 {
     if (hhook == IntPtr.Zero)
     {
         SendKeysHookProc proc1 = new SendKeysHookProc();
         hook     = new System.Windows.Forms.NativeMethods.HookProc(proc1.Callback);
         stopHook = false;
         hhook    = UnsafeNativeMethods.SetWindowsHookEx(1, hook, new HandleRef(null, UnsafeNativeMethods.GetModuleHandle(null)), 0);
         if (hhook == IntPtr.Zero)
         {
             throw new SecurityException(System.Windows.Forms.SR.GetString("SendKeysHookFailed"));
         }
     }
 }
Exemple #2
0
 private static void TestHook()
 {
     hookSupported = false;
     try
     {
         System.Windows.Forms.NativeMethods.HookProc pfnhook = new System.Windows.Forms.NativeMethods.HookProc(SendKeys.EmptyHookCallback);
         IntPtr handle = UnsafeNativeMethods.SetWindowsHookEx(1, pfnhook, new HandleRef(null, UnsafeNativeMethods.GetModuleHandle(null)), 0);
         hookSupported = new bool?(handle != IntPtr.Zero);
         if (handle != IntPtr.Zero)
         {
             UnsafeNativeMethods.UnhookWindowsHookEx(new HandleRef(null, handle));
         }
     }
     catch
     {
     }
 }
 private void UninstallMessageHook()
 {
     lock (this)
     {
         if (this.messageHookHandle != IntPtr.Zero)
         {
             System.Windows.Forms.UnsafeNativeMethods.UnhookWindowsHookEx(new HandleRef(this, this.messageHookHandle));
             this.hookProc = null;
             this.messageHookHandle = IntPtr.Zero;
             this.isHooked = false;
         }
     }
 }
 private void InstallMessageHook()
 {
     lock (this)
     {
         if (this.messageHookHandle == IntPtr.Zero)
         {
             this.hookProc = new System.Windows.Forms.NativeMethods.HookProc(this.MessageHookProc);
             this.messageHookHandle = System.Windows.Forms.UnsafeNativeMethods.SetWindowsHookEx(3, this.hookProc, new HandleRef(null, IntPtr.Zero), System.Windows.Forms.SafeNativeMethods.GetCurrentThreadId());
             if (this.messageHookHandle != IntPtr.Zero)
             {
                 this.isHooked = true;
             }
         }
     }
 }
 private void HookMouse()
 {
     GC.KeepAlive(this);
     lock (this)
     {
         if (this.mouseHookHandle == IntPtr.Zero)
         {
             if (this.thisProcessID == 0)
             {
                 System.Windows.Forms.SafeNativeMethods.GetWindowThreadProcessId(new HandleRef(this.control, this.control.Handle), out this.thisProcessID);
             }
             MouseHookObject obj1 = new MouseHookObject(this);
             System.Windows.Forms.NativeMethods.HookProc proc = new System.Windows.Forms.NativeMethods.HookProc(obj1.Callback);
             this.mouseHookRoot = GCHandle.Alloc(proc);
             this.mouseHookHandle = System.Windows.Forms.UnsafeNativeMethods.SetWindowsHookEx(7, proc, System.Windows.Forms.NativeMethods.NullHandleRef, System.Windows.Forms.SafeNativeMethods.GetCurrentThreadId());
         }
     }
 }
 private static void TestHook()
 {
     hookSupported = false;
     try
     {
         System.Windows.Forms.NativeMethods.HookProc pfnhook = new System.Windows.Forms.NativeMethods.HookProc(SendKeys.EmptyHookCallback);
         IntPtr handle = UnsafeNativeMethods.SetWindowsHookEx(1, pfnhook, new HandleRef(null, UnsafeNativeMethods.GetModuleHandle(null)), 0);
         hookSupported = new bool?(handle != IntPtr.Zero);
         if (handle != IntPtr.Zero)
         {
             UnsafeNativeMethods.UnhookWindowsHookEx(new HandleRef(null, handle));
         }
     }
     catch
     {
     }
 }
 private static void InstallHook()
 {
     if (hhook == IntPtr.Zero)
     {
         SendKeysHookProc proc1 = new SendKeysHookProc();
         hook = new System.Windows.Forms.NativeMethods.HookProc(proc1.Callback);
         stopHook = false;
         hhook = UnsafeNativeMethods.SetWindowsHookEx(1, hook, new HandleRef(null, UnsafeNativeMethods.GetModuleHandle(null)), 0);
         if (hhook == IntPtr.Zero)
         {
             throw new SecurityException(System.Windows.Forms.SR.GetString("SendKeysHookFailed"));
         }
     }
 }