コード例 #1
0
ファイル: MouseHook.cs プロジェクト: scslmd/Winook
        protected override void OnMessageReceived(object sender, MessageEventArgs e)
        {
            Contract.Requires(e != null);

            var eventArgs = new MouseMessageEventArgs
            {
                MessageCode = BitConverter.ToInt32(e.Bytes, 0),
                X           = BitConverter.ToInt32(e.Bytes, 4),
                Y           = BitConverter.ToInt32(e.Bytes, 8),
                Handle      = BitConverter.ToInt32(e.Bytes, 12),
                HitTestCode = BitConverter.ToInt32(e.Bytes, 16),
                Delta       = BitConverter.ToInt16(e.Bytes, 20),
            };

            Debug.WriteLine($"Mouse Message Code: {eventArgs.MessageCode}; X: {eventArgs.X}; Y: {eventArgs.Y}; Delta: {eventArgs.Delta}");

            if (eventArgs.MessageCode == LeftButtonUpMessageCode)
            {
                LeftButtonUp?.Invoke(this, eventArgs);
            }

            MessageReceived?.Invoke(this, eventArgs);
        }
コード例 #2
0
ファイル: MouseHook.cs プロジェクト: PeteyPii/Winook
        protected override void OnMessageReceived(object sender, MessageEventArgs e)
        {
            Contract.Requires(e != null);

            var eventArgs = new MouseMessageEventArgs
            {
                MessageCode = BitConverter.ToInt32(e.Bytes, 0),
                X           = BitConverter.ToInt32(e.Bytes, 4),
                Y           = BitConverter.ToInt32(e.Bytes, 8),
                Handle      = BitConverter.ToInt32(e.Bytes, 12),
                HitTestCode = BitConverter.ToInt32(e.Bytes, 16),
                Delta       = BitConverter.ToInt16(e.Bytes, 20),
            };

            Debug.WriteLine($"Code: {eventArgs.MessageCode}; X: {eventArgs.X}; Y: {eventArgs.Y}; Delta: {eventArgs.Delta}");

            MessageReceived?.Invoke(this, eventArgs);

            switch (GetMessageCode(eventArgs.MessageCode))
            {
            case MouseMessageCode.MouseMove:
                MouseMove?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.LeftButtonDown:
                LeftButtonDown?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.LeftButtonUp:
                LeftButtonUp?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.LeftButtonDblClk:
                LeftButtonDblClk?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.RightButtonDown:
                RightButtonDown?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.RightButtonUp:
                RightButtonUp?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.RightButtonDblClk:
                RightButtonDblClk?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.MiddleButtonDown:
                MiddleButtonDown?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.MiddleButtonUp:
                MiddleButtonUp?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.MiddleButtonDblClk:
                MiddleButtonDblClk?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.MouseWheel:
                MouseWheel?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.XButtonDown:
                XButtonDown?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.XButtonUp:
                XButtonUp?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.XButtonDblClk:
                XButtonDblClk?.Invoke(this, eventArgs);
                break;

            case MouseMessageCode.MouseHWheel:
                MouseHWheel?.Invoke(this, eventArgs);
                break;

            default:
                break;
            }

            if (_messageHandlers.ContainsKey(eventArgs.MessageCode))
            {
                _messageHandlers[eventArgs.MessageCode]?.Invoke(this, eventArgs);
            }
        }