| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1132 人关注过本帖
标题:用C#模拟的鼠标点击
只看楼主 加入收藏
yufd1986
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-11-19
收藏
 问题点数:0 回复次数:4 
用C#模拟的鼠标点击
程序代码:
using System;
using System.Collections.Generic;
using  System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace 鼠标单击模拟
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            timer1.Start();
        }
        [DllImport("user32.dll")]
        public static extern void mouse_event
            (
            int dwFlags, 
            int dx, 
            int dy, 
            int dwData,
            int dwExtraInfo
            );
        [DllImport("user32.dll")]
        static extern bool SetCursorPos(int X, int Y);  

        const int MOUSEEVENTF_MOVE = 0x0001;
        const int MOUSEEVENTF_LEFTDOWN = 0x0002;
        const int MOUSEEVENTF_LEFTUP = 0x0004;
        const int MOUSEEVENTF_RIGHTDOWN = 0x0008;
        const int MOUSEEVENTF_RIGHTUP = 0x0010;
        const int MOUSEEVENTF_MIDDLEDOWN = 0x0020;
        const int MOUSEEVENTF_MIDDLEUP = 0x0040;
        const int MOUSEEVENTF_ABSOLUTE = 0x8000; 
       private void button1_Click(object sender, EventArgs e)
        {
             timer2.Start();
            if (textBox3.Text != "")
                timer3.Start();
        }

        private void timer2_Tick(object sender, EventArgs e)
        { 
            int x,y;
            string[] str;
            str=textBox2.Text.Split(',');
            x=Convert.ToInt32(str[0]);
            y=Convert.ToInt32(str[1]);
            SetCursorPos(x, y);
            mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
            mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            Point pos = Cursor.Position;
            textBox1.Text = pos.X.ToString() +','+ pos.Y.ToString();
        }

        private void timer3_Tick(object sender, EventArgs e)
        {
            int x=0, y=0;
            string[] sta;
            sta = textBox3.Text.Split(',');
            x = Convert.ToInt32(sta[0]);
            y = Convert.ToInt32(sta[1]);
            SetCursorPos(x, y);
            mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
            mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);   
        }

        private void button2_Click(object sender, EventArgs e)
        {
            timer2.Stop();
            timer3.Stop();
        }
    }
}

输入2个坐标可以在屏幕的那2个坐标位置重复点击。

鼠标单击模拟.rar (34.81 KB)
搜索更多相关主题的帖子: 鼠标 模拟 
2008-04-21 17:42
野比
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:24
帖 子:1627
专家分:516
注 册:2007-5-24
收藏
得分:0 
收下~ 顶一个

女侠,约吗?
2008-04-22 14:24
xiaozhuml
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-5-5
收藏
得分:0 
顶啊 学习啊
2008-05-05 17:48
haibo5210
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-5-7
收藏
得分:0 
taiku
2008-05-07 20:08
快速回复:用C#模拟的鼠标点击
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018236 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved