欢迎来到我的的博客园,祝大家学有所成,早点实现自己的人生理想。

调用WindowApi来控制鼠标

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);
        }
  
    }
}

  

posted @ 2013-04-16 20:25  宋兴柱  阅读(1198)  评论(0编辑  收藏  举报