Exemplo n.º 1
0
        protected override int GlobalHookId => 14; //  WH_MOUSE_LL

        protected override IntPtr Callback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                if (HookMode.Local.Equals(Mode))
                {
                    var ms = Marshal.PtrToStructure <MOUSEHOOKSTRUCT>(lParam);

                    // Console.WriteLine("{0}, {1}", ms.x, ms.y);
                }

                if (HookMode.Global.Equals(Mode))
                {
                    var ms = Marshal.PtrToStructure <MSLLHOOKSTRUCT>(lParam);

                    switch (wParam.ToInt32())
                    {
                    case WM_MOUSEMOVE:
                        OnMove?.Invoke(new MouseHookEventArgs(MK_NONE, ms.flags, ms.time, ms.data, ms.x, ms.y));
                        break;

                    case WM_MOUSEWHEEL:
                        OnWheel?.Invoke(new MouseHookEventArgs(MK_NONE, ms.flags, ms.time, ms.data, ms.x, ms.y));
                        break;

                    case WM_MBUTTONDOWN:
                        HandleKeyDownHookEvent(new MouseHookEventArgs(MK_MBUTTON, ms.flags, ms.time, ms.data, ms.x, ms.y));
                        break;

                    case WM_LBUTTONDOWN:
                        HandleKeyDownHookEvent(new MouseHookEventArgs(MK_LBUTTON, ms.flags, ms.time, ms.data, ms.x, ms.y));
                        break;

                    case WM_RBUTTONDOWN:
                        HandleKeyDownHookEvent(new MouseHookEventArgs(MK_RBUTTON, ms.flags, ms.time, ms.data, ms.x, ms.y));
                        break;

                    case WM_MBUTTONUP:
                        HandleKeyReleasedHookEvent(new MouseHookEventArgs(MK_MBUTTON, ms.flags, ms.time, ms.data, ms.x, ms.y));
                        break;

                    case WM_LBUTTONUP:
                        HandleKeyReleasedHookEvent(new MouseHookEventArgs(MK_LBUTTON, ms.flags, ms.time, ms.data, ms.x, ms.y));
                        break;

                    case WM_RBUTTONUP:
                        HandleKeyReleasedHookEvent(new MouseHookEventArgs(MK_RBUTTON, ms.flags, ms.time, ms.data, ms.x, ms.y));
                        break;
                    }
                }
            }

            return(WinAPI.CallNextHookEx(instance, nCode, wParam, lParam));
        }
        internal void DispatchEvent(Map map, MapJsEventArgs eventArgs)
        {
            switch (eventArgs.Type)
            {
            case "click":
                OnClick?.Invoke(new MapMouseEventArgs(map, eventArgs));
                break;

            case "contextmenu":
                OnContextMenu?.Invoke(new MapMouseEventArgs(map, eventArgs));
                break;

            case "dblclick":
                OnDblClick?.Invoke(new MapMouseEventArgs(map, eventArgs));
                break;

            case "layeradded":
                OnLayerAdded?.Invoke(new MapEventArgs(map, eventArgs.Type));
                break;

            case "layerremoved":
                OnLayerRemoved?.Invoke(new MapEventArgs(map, eventArgs.Type));
                break;

            case "mousedown":
                OnMouseDown?.Invoke(new MapMouseEventArgs(map, eventArgs));
                break;

            case "mouseenter":
                OnMouseEnter?.Invoke(new MapMouseEventArgs(map, eventArgs));
                break;

            case "mouseleave":
                OnMouseLeave?.Invoke(new MapMouseEventArgs(map, eventArgs));
                break;

            case "mousemove":
                OnMouseMove?.Invoke(new MapMouseEventArgs(map, eventArgs));
                break;

            case "mouseout":
                OnMouseOut?.Invoke(new MapMouseEventArgs(map, eventArgs));
                break;

            case "mouseover":
                OnMouseOver?.Invoke(new MapMouseEventArgs(map, eventArgs));
                break;

            case "mouseup":
                OnMouseUp?.Invoke(new MapMouseEventArgs(map, eventArgs));
                break;

            case "touchcancel":
                OnTouchCancel?.Invoke(new MapTouchEventArgs(map, eventArgs));
                break;

            case "touchend":
                OnTouchEnd?.Invoke(new MapTouchEventArgs(map, eventArgs));
                break;

            case "touchmove":
                OnTouchMove?.Invoke(new MapTouchEventArgs(map, eventArgs));
                break;

            case "touchstart":
                OnTouchStart?.Invoke(new MapTouchEventArgs(map, eventArgs));
                break;

            case "wheel":
                OnWheel?.Invoke(new MapEventArgs(map, eventArgs.Type));
                break;
            }
        }