private void InvokeEventListeners(KeyState state, VirtualKeyCode key, int x, int y)
 {
     Task.Factory.StartNew(() =>
     {
         OnMouseEvent?.Invoke(state, key, x, y);
     });
 }
Beispiel #2
0
        private void doubleClickTimer_Tick(object sender, EventArgs e)
        {
            _milliseconds += 600;

            if (_milliseconds >= SystemInformation.DoubleClickTime)
            {
                _doubleClickTimer.Stop();

                if (_isDoubleClick)
                {
                    OnMouseEvent?.Invoke(this, new MouseEventArgs(MouseButtons.Left, 2, 0, 0, 0));
                }
                else
                {
                    if ((_lastButton & MouseButtons.Left) != 0)
                    {
                        OnMouseEvent?.Invoke(this, new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0));
                    }

                    if ((_lastButton & MouseButtons.Right) != 0)
                    {
                        OnMouseEvent?.Invoke(this, new MouseEventArgs(MouseButtons.Right, 1, 0, 0, 0));
                    }
                }

                _isFirstClick  = true;
                _isDoubleClick = false;
                _milliseconds  = 0;
            }
        }
        private void MouseHook_OnMouseEvent(KeyState state, VirtualKeyCode key, int x, int y)
        {
            if (OnMouseEvent != null)
            {
                Task.Factory.StartNew(() =>
                {
                    OnMouseEvent?.Invoke(state, key, x, y);
                });
            }

            if (mapKeyState.ContainsKey(key))
            {
                mapKeyState[key] = state == KeyState.Up && mapKeyState[key] == KeyState.Down
                    ? KeyState.Pressed
                    : state;
            }

            Task.Factory.StartNew(() =>
            {
                var currentKeyCallbackDict = singleKeyCallback; // create a temp var to avoid locking

                if (currentKeyCallbackDict != null && currentKeyCallbackDict.Count != 0)
                {
                    if (currentKeyCallbackDict.ContainsKey(key))
                    {
                        var currentList = currentKeyCallbackDict[key];

                        foreach (var callback in currentList)
                        {
                            callback(state, key);
                        }
                    }
                }
            });
        }
Beispiel #4
0
        public InputMapper(Form form, Panel panel)
        {
            _stopwatch.Start();

            panel.MouseDown += (sender, args) =>
            {
                _isMouseDown = true;
                bool inDoubleClickInterval = _stopwatch.ElapsedMilliseconds < SystemInformation.DoubleClickTime;
                bool inDoubleClickDistance = Math.Abs(_lastClickPos.X - args.X) < SystemInformation.DoubleClickSize.Width &&
                                             Math.Abs(_lastClickPos.Y - args.Y) < SystemInformation.DoubleClickSize.Height;
                if (inDoubleClickInterval && inDoubleClickDistance)
                {
                    _clicks++;
                }
                else
                {
                    _clicks = 1;
                }
                _stopwatch.Restart();
                _lastClickPos = args.Location;
                OnMouseEvent?.Invoke(sender, new MouseEventItem(MouseEvent.MOUSE_PRESSED, args.X, args.Y, _clicks));
            };
            panel.MouseUp += (sender, args) =>
            {
                OnMouseEvent?.Invoke(sender, new MouseEventItem(MouseEvent.MOUSE_RELEASED, args.X, args.Y, _clicks));
                if (!_isDragging)
                {
                    OnMouseEvent?.Invoke(sender, new MouseEventItem(MouseEvent.MOUSE_CLICKED, args.X, args.Y, _clicks));
                }
                _isMouseDown = false;
                _isDragging  = false;
            };
            panel.MouseMove += (sender, args) =>
            {
                if (_isMouseDown && args.Location != _lastClickPos)
                {
                    _isDragging = true;
                    OnMouseEvent?.Invoke(sender, new MouseEventItem(MouseEvent.MOUSE_DRAGGED, args.X, args.Y, 0));
                }
            };
            form.KeyDown += (sender, args) =>
            {
                OnKeyEvent?.Invoke(sender, new KeyEventItem(KeyEvent.KEY_PRESSED, (int)args.KeyCode, KeyToChar(args)));
            };
            form.KeyPress += (sender, args) =>
            {
                OnKeyEvent?.Invoke(sender, new KeyEventItem(KeyEvent.KEY_TYPED, KeyEvent.VK_UNDEFINED, args.KeyChar));
            };
            form.KeyUp += (sender, args) =>
            {
                OnKeyEvent?.Invoke(sender, new KeyEventItem(KeyEvent.KEY_RELEASED, (int)args.KeyCode, KeyToChar(args)));
            };
        }
Beispiel #5
0
        public static void OnMouseUp(MouseButtons Btn, int X, int Y)
        {
            var Index = MouseToIndex(Btn);

            MousePreState_[Index] = MouseCurState_[Index];
            MouseCurState_[Index] = false;
            MouseClickPos_[Index] = Point.Empty;

            MousePreDeltaPos_ = MouseCurDeltaPos_;
            MouseCurDeltaPos_ = Point.Empty;

            OnMouseEvent?.Invoke(Btn, X, Y, false, false);
        }
Beispiel #6
0
        public static void OnMouseMove(MouseButtons Btn, int X, int Y)
        {
            var Index = MouseToIndex(Btn);

            if (MouseCurState_[Index])
            {
                MousePreDeltaPos_   = MouseCurDeltaPos_;
                MouseCurDeltaPos_.X = MouseClickPos_[Index].X - X;
                MouseCurDeltaPos_.Y = MouseClickPos_[Index].Y - Y;
            }

            MousePos_.X = X;
            MousePos_.Y = Y;

            OnMouseEvent?.Invoke(Btn, X, Y, MouseCurState_[Index], true);
        }
Beispiel #7
0
 private void InvokeEventListeners(KeyState state, VirtualKeyCode key, int x = 0, int y = 0)
 {
     Task.Factory.StartNew(() => OnMouseEvent?.Invoke(key, state, x, y));
 }
Beispiel #8
0
 public void OnPointerEnter(PointerEventData eventData)
 {
     MouseOverEvent.Invoke(true);
 }