码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2017-08-27 16:15:25      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:window   user   ops   names   ica   win   鼠标   学习笔记   ice   

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#学习笔记】鼠标控制

标签:window   user   ops   names   ica   win   鼠标   学习笔记   ice   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!