首页 > Windows开发 > 详细

【C#学习笔记】鼠标控制

时间:2017-08-27 15:57:04      阅读:289      评论:0      收藏:0      [点我收藏+]
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();
        }
    }
}

 

【C#学习笔记】鼠标控制

原文:http://www.cnblogs.com/tiandsp/p/7440449.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!