示例#1
0
 public void Dispose()
 {
     if (MouseGlobalHook.hHook == 0)
     {
         return;
     }
     MouseGlobalHook.UnhookWindowsHookEx(MouseGlobalHook.hHook);
     MouseGlobalHook.hHook = 0;
 }
示例#2
0
 public MouseGlobalHook()
 {
     if (MouseGlobalHook.hHook == 0)
     {
         MouseGlobalHook.m_MouseHookProcedure = new MouseGlobalHook.HookProc(MouseHookProc);
         MouseGlobalHook.hHook = MouseGlobalHook.SetWindowsHookEx(14, MouseGlobalHook.m_MouseHookProcedure, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), 0);
         if (MouseGlobalHook.hHook == 0)
         {
             MessageBox.Show("SetWindowsHookEx Failed");
         }
     }
 }
示例#3
0
 private int MouseHookProc(int nCode, int wParam, IntPtr lParam)
 {
     if (nCode >= 0)
     {
         MouseGlobalHook.MouseLLHookStruct mouseLlHookStruct = (MouseGlobalHook.MouseLLHookStruct)Marshal.PtrToStructure(lParam, typeof(MouseGlobalHook.MouseLLHookStruct));
         MouseButtons   button = MouseButtons.None;
         short          num    = 0;
         int            clicks = 0;
         MouseEventArgs e      = new MouseEventArgs(button, clicks, mouseLlHookStruct.Point.X, mouseLlHookStruct.Point.Y, (int)num);
         if (MouseMove != null && (MouseGlobalHook.m_OldX != mouseLlHookStruct.Point.X || MouseGlobalHook.m_OldY != mouseLlHookStruct.Point.Y))
         {
             MouseGlobalHook.m_OldX = mouseLlHookStruct.Point.X;
             MouseGlobalHook.m_OldY = mouseLlHookStruct.Point.Y;
             if (MouseMove != null)
             {
                 MouseMove((object)null, e);
             }
         }
     }
     return(MouseGlobalHook.CallNextHookEx(MouseGlobalHook.hHook, nCode, wParam, lParam));
 }
示例#4
0
		public static extern int SetWindowsHookEx(int idHook, MouseGlobalHook.HookProc lpfn, IntPtr hInstance, int threadId);