C#模拟window操作鼠标的方法
程序员文章站
2023-12-09 20:11:03
本文实例讲述了c#模拟window操作鼠标的方法。分享给大家供大家参考。具体实现方法如下:
using system;
using system.collect...
本文实例讲述了c#模拟window操作鼠标的方法。分享给大家供大家参考。具体实现方法如下:
using system; using system.collections.generic; using system.text; using system.runtime.interopservices; namespace winapi { class program { [dllimport("user32.dll", entrypoint = "mouse_event", setlasterror = true)] private static extern int mouse_event(int dwflags, int dx, int dy, int cbuttons, int dwextrainfo); const int mouseeventf_move = 0x0001; // 移动鼠标 const int mouseeventf_leftdown = 0x0002;// 模拟鼠标左键按下 const int mouseeventf_leftup = 0x0004; //模拟鼠标左键抬起 const int mouseeventf_rightdown = 0x0008; //模拟鼠标右键按下 const int mouseeventf_rightup = 0x0010;// 模拟鼠标右键抬起 const int mouseeventf_middledown = 0x0020; //模拟鼠标中键按下 const int mouseeventf_middleup = 0x0040; //模拟鼠标中键抬起 const int mouseeventf_absolute = 0x8000; //标示是否采用绝对坐标 static void main(string[] args) { // 移动鼠标 mouse_event(mouseeventf_move, 400, 0, 0, 0); //点击鼠标右键 mouse_event(mouseeventf_rightdown | mouseeventf_rightup, 410, 0, 0, 0); console.readline(); } } }
希望本文所述对大家的c#程序设计有所帮助。