private async void MouseMoveHook_Move(object sender, MouseHookEventArgs e)
        {
            if ((DateTime.UtcNow - lastMouseEvent).TotalSeconds > Config.MaxEventRate)
            {
                // Returns immediately if semaphore is already taken
                if (!await semSlim.WaitAsync(0))
                {
                    return;
                }

                try
                {
                    IElement element = Svc.SM.UI.ElementWdw.CurrentElement;
                    string   content = GetContent() ?? string.Empty;
                    if (element == null)
                    {
                        return;
                    }
                    await eventStore.AddEvent(new SMEvent(element, content, EventOrigin.Mouse));

                    lastMouseEvent = DateTime.UtcNow;
                }
                finally
                {
                    semSlim.Release();
                }
            }
        }
        private void OnMove(MouseHookEventArgs e)
        {
            if (Svc.SM.UI.ElementWdw.IsAvailable)
            {
                IntPtr SMElementWdw  = Svc.SM.UI.ElementWdw.Handle;
                IntPtr ForegroundWdw = Natives.GetForegroundWindow();

                if (SMElementWdw == ForegroundWdw)
                {
                    Move?.Invoke(this, e);
                }
            }
        }
 /// <summary>
 ///     This is the callback method that is called whenever a low level mouse event is triggered.
 ///     We use it to call our individual custom events.
 /// </summary>
 private IntPtr MouseHookCallback(int nCode, IntPtr wParam, IntPtr lParam)
 {
     if (nCode >= 0)
     {
         var lParamStruct = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
         var e            = new MouseHookEventArgs(lParamStruct);
         switch ((MouseMessages)wParam)
         {
         case MouseMessages.WmMouseMove:
             TriggerMouseEvent(e, MouseEventNames.MouseMove, OnMove);
             break;
         }
     }
     return((IntPtr)Natives.CallNextHookEx(_hookId, nCode, wParam, lParam));
 }
 private static void TriggerMouseEvent(MouseHookEventArgs e, MouseEventNames name,
                                       Action <MouseHookEventArgs> method)
 {
     e.MouseEventName = name;
     method(e);
 }