码迷,mamicode.com
首页 > 其他好文 > 详细

模拟鼠标操作

时间:2019-01-18 21:19:45      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:ima   知识   lock   vat   send   技术   image   9.png   class   

实现效果:

  技术分享图片

知识运用:
  API函数mouse_event    //模拟鼠标的事件

[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall)]
public extern static IntPtr mouse_event(Int32 dwFlag,Int32 dx,Int32 dy,Int32 dwData,Int32 dwExtraInfo);

技术分享图片

实现代码:

        [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall)]
        public extern static IntPtr mouse_event(Int32 dwFlag,Int32 dx,Int32 dy,Int32 dwData,Int32 dwExtraInfo);
        public const int MOOSEEVENTF_MOVE = 0x0001;             //表示鼠标移动
        public const int MOOSEEVENTF_LEFTDOWN = 0x0002;         //表示鼠标左键按下
        public const int MOOSEEVENTF_LEFTUP = 0x0004;           //表示鼠标左键松开
        private void button1_Click(object sender, EventArgs e)
        {
            mouse_event(MOOSEEVENTF_MOVE,-20,-20,0,0);
            mouse_event(MOOSEEVENTF_LEFTDOWN,0,0,0,0);
            mouse_event(MOOSEEVENTF_LEFTUP,0,0,0,0);
            mouse_event(MOOSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
            mouse_event(MOOSEEVENTF_LEFTUP, 0, 0, 0, 0);
        }

  

模拟鼠标操作

标签:ima   知识   lock   vat   send   技术   image   9.png   class   

原文地址:https://www.cnblogs.com/feiyucha/p/10289580.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!