c#实现自动点击鼠标左键(例子)
2010-05-21 23:33
369 查看
C# code
using System; using System.Collections.Generic; using System.ComponentModel; 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(); } [DllImport("User32")] public extern static void mouse_event(int dwFlags, int dx, int dy, int dwData, IntPtr dwExtraInfo); [DllImport("User32")] public extern static void SetCursorPos(int x, int y); [DllImport("User32")] public extern static bool GetCursorPos(out POINT p); [StructLayout(LayoutKind.Sequential)] public struct POINT { public int X; public int Y; } public enum MouseEventFlags { Move = 0x0001, LeftDown = 0x0002, LeftUp = 0x0004, RightDown = 0x0008, RightUp = 0x0010, MiddleDown = 0x0020, MiddleUp = 0x0040, Wheel = 0x0800, Absolute = 0x8000 } private void AutoClick(int x, int y) { POINT p = new POINT(); GetCursorPos(out p); try { SetCursorPos(x, y); mouse_event((int)(MouseEventFlags.LeftDown | MouseEventFlags.Absolute), 0, 0, 0, IntPtr.Zero); mouse_event((int)(MouseEventFlags.LeftUp | MouseEventFlags.Absolute), 0, 0, 0, IntPtr.Zero); } finally { SetCursorPos(p.X, p.Y); } } private void button1_Click(object sender, EventArgs e) { AutoClick(20, 40); } } }
相关文章推荐
- 用jq实现点击右边内容实现,左边内容切换、自动切换,当鼠标放上右边li上面,左边内容停止切换。
- C# 实现按钮自动点击
- 软件在指定时间间隔内无鼠标移动键盘点击等动作自动锁定的实现
- jQuery实现文本域内提示文字,当鼠标点击进文本域后自动消失,文本域失去鼠标焦点后显示提示文字或显示用户输入的文字。
- 在C#中实现对ListView点击列标题自动排序功能
- C# 中TreeView 控件实现点击CheckBoX自动打钩的事件
- 在C#中实现对ListView点击列标题自动排序功能
- C#中winform实现自动触发鼠标、键盘事件的方法
- 点击button按钮后,启动一个实现鼠标拖动另一个button的线程 (JFrame/C# WinForm)
- Excel之实现鼠标点击完成自动累加功能
- 在C#中实现对ListView点击列标题自动排序功能
- 在C#中实现对ListView点击列标题自动排序功能
- 实现鼠标自动点击
- YUI实现鼠标自动点击
- 在C#中实现对ListView点击列标题自动排序功能
- C#实现百度自动点击软件设计
- C#WinForm应用程序实现自动填充网页上的用户名和密码并点击登录按钮【转载】
- 在C#中实现对ListView点击列标题自动排序功能
- 全文检索等鼠标滑上去(不用点击),里面提示文字要自动消失效果的实现。
- 在C#中实现对ListView点击列标题自动排序功能