[go: up one dir, main page]

Menu

[605fd9]: / Form1.cs  Maximize  Restore  History

Download this file

100 lines (95 with data), 3.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MouseClickTool
{/// <summary>
/// 怎么简单怎么来了
/// </summary>
public partial class Form1 : Form
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, IntPtr dwExtraInfo);
private const uint RightDown = 0x0008;
private const uint RightUp = 0x0010;
private const uint LeftDown = 0x0002;
private const uint LeftUp = 0x0004;
public static void SendRightClick(uint posX, uint posY)
{
mouse_event(RightDown, posX, posY, 0, new System.IntPtr());
mouse_event(RightUp, posX, posY, 0, new System.IntPtr());
}
public static void SendLeftClick(uint posX, uint posY)
{
mouse_event(LeftDown, posX, posY, 0, new System.IntPtr());
mouse_event(LeftUp, posX, posY, 0, new System.IntPtr());
}
public Form1()
{
InitializeComponent();
this.comboBox1.SelectedIndex = 0;
}
private void is_begin_Click(object sender, EventArgs e)
{
if (is_begin.Text == "停止")
{
Environment.Exit(0);
return;
}
string ms = is_ms.Text;
int result;
if (int.TryParse(ms, out result) && result > 0)
{
is_ms.ReadOnly = true;
Task.Factory.StartNew(async () =>
{
await Task.Run(() =>
{
for (int i = 1; i < 5; i++)
{
is_begin.Text = string.Format("开始({0})", 5 - i);
Thread.Sleep(1000);
}
});
is_begin.Text = string.Format("停止");
if (this.comboBox1.SelectedIndex == 0)
{
for (; ; )
{
await Task.Run(() =>
{
uint x = (uint)Cursor.Position.X;
uint y = (uint)Cursor.Position.Y;
SendLeftClick(x, y);
Thread.Sleep(result);
});
}
}
else
{
for (; ; )
{
await Task.Run(() =>
{
uint x = (uint)Cursor.Position.X;
uint y = (uint)Cursor.Position.Y;
SendRightClick(x, y);
Thread.Sleep(result);
});
}
}
});
}
else
{
MessageBox.Show("输入的数字不正确,必须是正整数");
}
}
}
}