您的位置:首页 > 编程语言 > C#

【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();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: