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

c# 调用API mouse_event 模拟鼠标事件

2011-02-12 21:56 731 查看
using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
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; //标示是否采用绝对坐标

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
mouse_event(MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_ABSOLUTE, 500, 400, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP , 500, 400, 0, 0);
}

[DllImport("user32", EntryPoint = "mouse_event")]
private static extern int mouse_event(
int dwFlags,// 下表中标志之一或它们的组合
int dx,
int dy, //指定x,y方向的绝对位置或相对位置
int cButtons,//没有使用
int dwExtraInfo//没有使用
);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: