您的位置:首页 > 其它

winform 判断鼠标在一段时间内是否移动

2012-04-06 15:40 239 查看
int x, y;
        DateTime start;

        public Form1()
        {
            InitializeComponent();

            x = Control.MousePosition.X;
            y = Control.MousePosition.Y;
            
            this.timer1.Enabled = true;
            this.timer1.Interval = 1000;
        }

        #region 判断鼠标在1分钟内是否移动
        bool ff = true;
        private void timer1_Tick_1(object sender, EventArgs e)
        {
            int x1 = Control.MousePosition.X;
            int y1 = Control.MousePosition.Y;

            if ((x == x1) && (y == y1) && ff)
            {
                start = DateTime.Now;
                ff = false;
            }
            if (x != x1 || y != y1)
            {
                x = x1;
                y = y1;
                start = DateTime.Now;
                ff = true;
            }

            TimeSpan ts = DateTime.Now.Subtract(start);

            //鼠标或键盘误动作1分钟后开始播放视频
            if (ts.Minutes >= 1)
            {
                //do something
            }
        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: