1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Windows.Forms;
5
6 namespace SuperDLL
7 {
8 /// <summary>
9 /// 键鼠操作
10 /// </summary>
11 public static class KeyMouse
12 {
13 [System.Runtime.InteropServices.DllImport("user32")]
14 public static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
15 //移动鼠标
16 const int MOUSEEVENTF_MOVE = 0x0001;
17 //模拟鼠标左键按下
18 const int MOUSEEVENTF_LEFTDOWN = 0x0002;
19 //模拟鼠标左键抬起
20 const int MOUSEEVENTF_LEFTUP = 0x0004;
21 //模拟鼠标右键按下
22 const int MOUSEEVENTF_RIGHTDOWN = 0x0008;
23 //模拟鼠标右键抬起
24 const int MOUSEEVENTF_RIGHTUP = 0x0010;
25 //模拟鼠标中键按下
26 const int MOUSEEVENTF_MIDDLEDOWN = 0x0020;
27 //模拟鼠标中键抬起
28 const int MOUSEEVENTF_MIDDLEUP = 0x0040;
29 //标示是否采用绝对坐标
30 const int MOUSEEVENTF_ABSOLUTE = 0x8000;
31 //鼠标滚轮移动
32 const int MOUSEEVENTF_WHEEL = 0x800;
33 /// <summary>
34 /// 鼠标点击
35 /// </summary>
36 /// <param name="X"></param>
37 /// <param name="Y"></param>
38 /// <param name="bl"></param>
39 /// <param name="width">1366</param>
40 /// <param name="height">768</param>
41 public static void MouseClick(int X, int Y, bool bl, int width, int height)
42 {
43 //移动
44 mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, X * 65536 / width, Y * 65536 / height, 0, 0);
45 if (bl == true)
46 {
47 //左键
48 mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X * 65536 / width, Y * 65536 / height, 0, 0);
49 }
50 else if (bl == false)
51 {
52 //右键
53 mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, X * 65536 / width, Y * 65536 / height, 0, 0);
54 }
55 }
56 /// <summary>
57 /// 鼠标滚轮向上
58 /// </summary>
59 /// <param name="x"></param>
60 public static void MouseUp(int x)
61 {
62 for (int i = 0; i < x; i++)
63 {
64 mouse_event(MOUSEEVENTF_WHEEL, 0, 0, 100, 0);
65 }
66 }
67 /// <summary>
68 /// 鼠标滚轮向下
69 /// </summary>
70 /// <param name="x"></param>
71 public static void MouseDown(int x)
72 {
73 for (int i = 0; i < x; i++)
74 {
75 mouse_event(MOUSEEVENTF_WHEEL, 0, 0, -100, 0);
76 }
77 }
78 /// <summary>
79 /// 系统剪切板拷贝
80 /// </summary>
81 /// <param name="content"></param>
82 public static void SystemCopy(string content)
83 {
84 Clipboard.SetDataObject(content);
85 IDataObject Get = Clipboard.GetDataObject();
86 string msg = (String)Get.GetData(DataFormats.Text);
87 MessageBox.Show(msg);
88 }
89 }
90 }