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

C#任意位置 模拟鼠标 点击 事件 并获取 鼠标 位置 源码

2012-09-05 18:39 701 查看


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.IO;

using System.Runtime.InteropServices;

using System.Threading;

namespace 模拟鼠标啊啊

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

[DllImport("user32.dll")]

static extern bool SetCursorPos(int x, int y);

[DllImport("user32.dll")]

static extern void mouse_event(MouseEventFlag flags, int dx, int dy, uint data, UIntPtr extraInfo);

[Flags]

enum MouseEventFlag : uint

{

Move = 0x0001,

LeftDown = 0x0002,

LeftUp = 0x0004,

RightDown = 0x0008,

RightUp = 0x0010,

MiddleDown = 0x0020,

MiddleUp = 0x0040,

XDown = 0x0080,

XUp = 0x0100,

Wheel = 0x0800,

VirtualDesk = 0x4000,

Absolute = 0x8000

}

private void Form1_MouseMove(object sender, MouseEventArgs e)

{

;

Point screenPoint = Control.MousePosition;//获取光标相对屏幕的距离

textBox1.Text = screenPoint.X.ToString();//获得鼠标x轴

textBox2.Text = screenPoint.Y.ToString();//获得鼠标y轴

}

public void xxx(int x,int y) { SetCursorPos(y, x);

mouse_event(MouseEventFlag.LeftDown, 10, 10, 0, UIntPtr.Zero);

mouse_event(MouseEventFlag.LeftUp, 10, 10, 0, UIntPtr.Zero);

}

private void Form1_MouseClick(object sender, MouseEventArgs e)

{

int x =Convert.ToInt32( textBox2.Text);

int y = Convert.ToInt32(textBox1.Text);

this.WindowState = FormWindowState.Minimized;

xxx(x, y);

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: