cmouse.cs

来自「一个Wince的小程序」· CS 代码 · 共 68 行

CS
68
字号
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication1
{
    class CMouse
    {
        private Microsoft.DirectX.Direct3D.Device mouse = null;
        public System.Threading.AutoResetEvent MouseUpdated;
        private float x, y, z = 0.0f;

        public float Z
        {
            get { return z; }
            set { z = value; }
        }

        public float Y
        {
            get { return y; }
            set { y = value; }
        }

        public float X
        {
            get { return x; }
            set { x = value; }
        }
        private byte[] buttons;

        public CMouse(System.Windows.Forms.Control control)
        {
            mouse = new Microsoft.DirectX.Direct3D.Device(SystemGuid.Mouse);
            mouse.setSetCooperativeLevel(control, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
            mouse.Properties.AxisModeAbsolute = false;
            MouseUpdated = new System.Threading.AutoResetEvent(false);
            mouse.SetEventNotification(MouseUpdated);
            mouse.Acquire();
            Update();

        }
        public void Update()
        {
            MouseState state = mouse.CurrentMouseState;
            x = state.X;
            y = state.Y;
            z = state.Z;
            buttons = state.GetMouseButtons();
        }

        public bool LeftButtonDown
        {
            get
            {
                bool a;
                return a = (buttons[0] != 0);
            }
        }


    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?