public MouseInterceptorOperation(
     ILogger logger,
     IMouseInterceptor mouseInterceptor,
     INativeMethods nativeMethods)
 {
     this.logger           = logger;
     this.mouseInterceptor = mouseInterceptor;
     this.nativeMethods    = nativeMethods;
 }
        public void DeregisterMouseHook(IMouseInterceptor interceptor)
        {
            var hook = MouseHooks.Values.FirstOrDefault(h => h.Interceptor == interceptor);

            if (hook != null)
            {
                var success = hook.Detach();

                if (!success)
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }

                MouseHooks.TryRemove(hook.Handle, out _);
            }
        }
        public void RegisterMouseHook(IMouseInterceptor interceptor)
        {
            var hookReadyEvent = new AutoResetEvent(false);
            var hookThread     = new Thread(() =>
            {
                var hook       = new MouseHook(interceptor);
                var sleepEvent = new AutoResetEvent(false);

                hook.Attach();
                MouseHooks[hook.Handle] = hook;
                hookReadyEvent.Set();

                while (true)
                {
                    sleepEvent.WaitOne();
                }
            });

            hookThread.SetApartmentState(ApartmentState.STA);
            hookThread.IsBackground = true;
            hookThread.Start();

            hookReadyEvent.WaitOne();
        }
 public MouseInterceptorOperation(ClientContext context, ILogger logger, IMouseInterceptor mouseInterceptor) : base(context)
 {
     this.logger           = logger;
     this.mouseInterceptor = mouseInterceptor;
 }
Esempio n. 5
0
 internal MouseHook(IMouseInterceptor interceptor)
 {
     Interceptor = interceptor;
 }