【C#学习笔记】鼠标控制
2017-08-27 15:14
369 查看
using System; using System.Runtime.InteropServices; using System.Windows.Forms; namespace ConsoleApplication1 { class Program { public struct POINT { public int x, y; } const int MOUSEEVENTF_LEFTDOWN = 0x2; const int MOUSEEVENTF_LEFTUP = 0x4; const int MOUSEEVENTF_RIGHTDOWN = 0x8; const int MOUSEEVENTF_RIGHTUP = 0x10; const int MOUSEEVENTF_MIDDLEDOWN = 0x20; const int MOUSEEVENTF_MIDDLEUP = 0x40; const int MOUSEEVENTF_MOVE = 0x1; [DllImport("user32.dll")] public static extern int GetCursorPos(ref POINT p); [DllImport("user32.dll")] public static extern int SetCursorPos(int x, int y); [DllImport("user32.dll")] public static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); static void Main(string[] args) { POINT p=new POINT(); GetCursorPos(ref p); Console.WriteLine(p.x + " " + p.y); SetCursorPos(0, 0); mouse_event(MOUSEEVENTF_RIGHTDOWN, p.x, p.y, 0, 0); mouse_event(MOUSEEVENTF_RIGHTUP, p.x, p.y, 0, 0); Console.Read(); } } }
相关文章推荐
- 【C#学习笔记】鼠标控制
- (原创)c#学习笔记04--流程控制02--goto语句
- (原创)c#学习笔记04--流程控制03--分支02--if语句
- Python学习笔记(十七)——用GUI自动化控制键盘鼠标
- [学习笔记]Asp.net(C#)菜鸟进级系列之流程控制
- 工作学习笔记——C#自定义类型剪贴板操作、自定义鼠标光标定位问题
- (原创)c#学习笔记04--流程控制03--分支01--三元运算符
- (原创)c#学习笔记04--流程控制04--循环03--for循环
- IntelliJ IDEA 学习笔记 - 鼠标滚轮控制缩放大小
- (原创)c#学习笔记04--流程控制04--循环04--循环中断和无限循环
- Java学习笔记 Java调用Win32 API控制鼠标活动范围
- C#学习笔记 控制流
- (原创)c#学习笔记04--流程控制04--循环02--while循环
- (原创)c#学习笔记04--流程控制01--布尔逻辑01--布尔赋值运算符
- (原创)c#学习笔记04--流程控制03--分支03--switch语句
- 用C#控制TQ2440开发板上的LED小灯(C# GPIO学习笔记)
- Baxter学习笔记6-鼠标点动控制baxter机械臂--实战篇
- C#学习之路,学习笔记 第四章 流程控制
- (原创)c#学习笔记04--流程控制01--布尔逻辑02--按位运算符
- 用C#控制TQ2440开发板上的LED小灯(C# GPIO学习笔记)