SetWindowsHookEx with WH_MOUSE_LL slows down the mouse for several seconds


I am using the following code to get mouse messages on the current process.

using (Process curProcess = Process.GetCurrentProcess())
using (ProcessModule curModule = curProcess.MainModule)
    return SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle(curModule.ModuleName), 0);

For some reason when this code runs the mouse get slow for several seconds and then back to normal.

Any ideas?

EDIT - hook method

private static IntPtr mouseEvent(int nCode, IntPtr wParam, IntPtr lParam)
    if (nCode >= 0 && MouseMessages.WM_LBUTTONDOWN == (MouseMessages)wParam)
        MSLLHOOKSTRUCT hookStruct = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
        LastLeftClick = new ClickInfo { Time = DateTime.Now, X =, Y = };
    return CallNextHookEx(hookID, nCode, wParam, lParam);

public class ClickInfo
    public int X { get; set; }
    public int Y { get; set; }
    public DateTime Time { get; set; }

What does your hook procedure look like?

If your process only has one UI thread, use a Message Filter instead: