zoukankan      html  css  js  c++  java
  • C#对鼠标的操作

    using System;
    using System.Drawing;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    
    namespace test
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            //获取双击间隔时间
            [DllImport("user32.dll", EntryPoint = "GetDoubleClickTime")]
            public extern static int GetDoubleClickTime(); 
            //获取鼠标键数目
            public const int SM_CMOUSEBUTTONS = 43;//定义一个常量值
            [DllImport("user32",EntryPoint="GetSystemMetrics")]
            public extern static int GetSystemMetrics(int intcoutn);
            private void Form1_Load(object sender, EventArgs e)
            {
                //设置定时器
                this.timer1.Enabled = true;
                this.timer1.Interval = 1000;
                this.label1.Text ="鼠标双击间隔时间是:"+GetDoubleClickTime() + "ms";
                this.label2.Text = "鼠标键数是:" + GetSystemMetrics(SM_CMOUSEBUTTONS) + "";
            }
    
            private void Form1_MouseMove(object sender, MouseEventArgs e)
            {
                //this.label3.Text = e.X.ToString();
                //this.label4.Text = e.Y.ToString();
            }
            //定时获取光标位置
            [DllImport("user32.dll")]
            private static extern bool GetCursorPos(out Point lpPoint);
            //定时设置光标位置  
            [DllImport("user32")]
            static extern bool SetCursorPos(int X, int Y);
            //发送鼠标消息
            [DllImport("user32.dll")]
            //引入API函数mouse_event
            private static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
            const int MOUSEEVENTF_MOVE = 0x0001;//表示鼠标移动
            const int MOUSEEVENTF_LEFTDOWN = 0x0002;//表示鼠标左键按下
            const int MOUSEEVENTF_LEFTUP = 0x0004;//表示鼠标左键松开
    
            private void timer1_Tick(object sender, EventArgs e)
            {
                Point ShowPoint = new Point();
                GetCursorPos(out ShowPoint);
                this.label3.Text = ShowPoint.X.ToString();
                this.label4.Text = ShowPoint.Y.ToString();
                //设置鼠标位置
                SetCursorPos(509,53);
                //发送左键按下消息
                mouse_event(MOUSEEVENTF_LEFTDOWN, 509, 53, 0, 0);
                //发送字符
                SendKeys.Send("a");
            }
        }
    }
  • 相关阅读:
    『转载』Git管理工具sourcetree安装与使用
    实用网站分享:全栈开发可能需要用到的网站
    低版本浏览器(IE6+)页面兼容性问题相关处理
    Git常用命令说明
    jquery的全局函数 多库并存
    深浅拷贝
    localStorage
    jquery中封装了三种ajax请求方式
    jquery的树状菜单
    自定义动画 jquery的结束动画
  • 原文地址:https://www.cnblogs.com/yuqilihualuo/p/3813983.html
Copyright © 2011-2022 走看看