调用WindowApi来控制鼠标
调用WindowApi来控制鼠标
title: 调用WindowApi来控制鼠标
date: 2013-04-16 12:25:00
tags:
- Windows API
- 鼠标控制
- 系统编程
- C/C++
- 自动化脚本
categories:
- Windows API
- 程序开发
- 系统编程
- 脚本编写
- 自动化
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace ISMS.WinServer.Utility
{
/// <summary>
///
/// </summary>
public class MouseApi
{
[DllImport("User32.dll")]
static extern void mouse_event(MouseEventFlag flags, int dx, int dy, uint data, UIntPtr extraInfo);
[Flags]
enum MouseEventFlag : uint
{
Move = 0x001, LeftDown = 0x0002, LeftUP = 0x0004, RightDown = 0x0008,
RightUp = 0x0010, MiddleDown = 0x0020, MiddleUP = 0x0040, Absolut = 0x8000, xDown = 0x0080, xUp = 0x0100, wheel = 0x0800, virtualDesk = 0x4000
}
public void LeftClick()
{
mouse_event(MouseEventFlag.LeftUP, 0, 0, 0, UIntPtr.Zero);
mouse_event(MouseEventFlag.LeftDown, 0, 0, 0, UIntPtr.Zero);
mouse_event(MouseEventFlag.LeftUP, 0, 0, 0, UIntPtr.Zero);
}
public void RightClick()
{
mouse_event(MouseEventFlag.RightUp, 0, 0, 0, UIntPtr.Zero);
mouse_event(MouseEventFlag.RightDown, 0, 0, 0, UIntPtr.Zero);
mouse_event(MouseEventFlag.RightUp, 0, 0, 0, UIntPtr.Zero);
}
public void MiddleClick()
{
mouse_event(MouseEventFlag.MiddleUP, 0, 0, 0, UIntPtr.Zero);
mouse_event(MouseEventFlag.MiddleDown, 0, 0, 0, UIntPtr.Zero);
mouse_event(MouseEventFlag.MiddleUP, 0, 0, 0, UIntPtr.Zero);
}
}
}
调用WindowApi来控制鼠标
https://www.dearcloud.cn/2013/04/16/20200310-cnblogs-old-posts/20130416-调用WindowApi来控制鼠标/