C#鼠标点击器-没有测试-转自http://hi.baidu.com/syq_ghost/item/2cc253eb538b72e7fb42ba44
C#鼠标点击器
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
using System.Text.RegularExpressions;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
[DllImport("user32")]
private static extern int mouse_event(int dwFlags,int dx,int dy,int cButtons,int dwExtraInfo);
const int MOUSEEVENT_LEFTDOWN = 0x0002;
const int MOUSEEVENT_LEFTUP = 0x0004;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string pattern=@"^\d+(\.\d)?$";
timer1.Enabled = true;
if (Regex.IsMatch(textBox2.Text, pattern))
{
timer1.Interval = int.Parse(this.textBox2.Text);
timer1.Start();
}
else
{
timer1.Stop();
timer1.Enabled = false;
MessageBox.Show("请输入整数!","系统提示:",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
private void Mouse_Click()
{
mouse_event(MOUSEEVENT_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENT_LEFTUP, 0, 0, 0, 0);
textBox2.Focus();
}
private void timer1_Tick(object sender, EventArgs e)
{
Mouse_Click();
}
private void Form1_Load(object sender, EventArgs e)
{
textBox2.Focus();
}
private void textBox2_Click(object sender, EventArgs e)
{
this.textBox2.SelectAll();
}
private void textBox2_KeyDown(object sender, KeyEventArgs e)
{
string pattern = @"^\d+(\.\d)?$";
if (e.KeyCode == Keys.PageUp)
{
if (Regex.IsMatch(textBox2.Text, pattern))
{
timer1.Enabled = true;
timer1.Interval = int.Parse(this.textBox2.Text);
timer1.Start();
}
else
{
timer1.Stop();
timer1.Enabled = false;
MessageBox.Show("错误:请输入整数!", "系统提示:", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else if (e.KeyCode == Keys.PageDown)
{
timer1.Enabled = true;
timer1.Stop();
}
}
}
}
C#同样能实现鼠标点击功能,我试着写了一个,玩游戏的朋友们应该用的着,希望对你们有用