6个回答
展开全部
获取鼠标点所在窗口的坐标或相对屏幕的坐标,然后你就可以做自己想做的了
using System;
using System.Collections.Generic;
using System.Text;
namespace MouseEvent
{
class Program
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
const int MOUSEEVENTF_MOVE = 0x0001;
const int MOUSEEVENTF_LEFTDOWN = 0x0002;
const int MOUSEEVENTF_LEFTUP = 0x0004;
const int MOUSEEVENTF_RIGHTDOWN = 0x0008;
const int MOUSEEVENTF_RIGHTUP = 0x0010;
const int MOUSEEVENTF_MIDDLEDOWN = 0x0020;
const int MOUSEEVENTF_MIDDLEUP = 0x0040;
const int MOUSEEVENTF_ABSOLUTE = 0x8000;
static void Main(string[] args)
{
for (int i = 0; i < 5; i++)
{
System.Threading.Thread.Sleep(1000);
//鼠标移动,坐标x,坐标y,只设置前三个参数就够了
mouse_event(MOUSEEVENTF_MOVE, 10, 0, 0, 0);
//鼠标左键点击
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace MouseEvent
{
class Program
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
const int MOUSEEVENTF_MOVE = 0x0001;
const int MOUSEEVENTF_LEFTDOWN = 0x0002;
const int MOUSEEVENTF_LEFTUP = 0x0004;
const int MOUSEEVENTF_RIGHTDOWN = 0x0008;
const int MOUSEEVENTF_RIGHTUP = 0x0010;
const int MOUSEEVENTF_MIDDLEDOWN = 0x0020;
const int MOUSEEVENTF_MIDDLEUP = 0x0040;
const int MOUSEEVENTF_ABSOLUTE = 0x8000;
static void Main(string[] args)
{
for (int i = 0; i < 5; i++)
{
System.Threading.Thread.Sleep(1000);
//鼠标移动,坐标x,坐标y,只设置前三个参数就够了
mouse_event(MOUSEEVENTF_MOVE, 10, 0, 0, 0);
//鼠标左键点击
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
}
}
}
展开全部
using System.Windows.Forms;
using System.Drawing;
Point point;
point = Cursor.Position; //获取鼠标位置
point = new Point(10, 10); //屏幕左上角为坐标原点 横坐标向右加 纵坐标向下加
Cursor.Position = point; //设置鼠标位置
using System.Drawing;
Point point;
point = Cursor.Position; //获取鼠标位置
point = new Point(10, 10); //屏幕左上角为坐标原点 横坐标向右加 纵坐标向下加
Cursor.Position = point; //设置鼠标位置
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在你的窗体代码中添加如下API定义代码(引人System.Runtime.InteropServices命名空间(using System.Runtime.InteropServices;)):
[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
}
[DllImport("user32.dll")]
static extern void mouse_event(MouseEventFlag flags, int dx, int dy, uint data, UIntPtr extraInfo);
在你的按钮单击事件中(Button_Click)加入如下代码:
Cursor.Position = new Point(0 /*x坐标*/, 0 /*y坐标*/); //这里是移动鼠标的代码
mouse_event(MouseEventFlag.LeftDown,0,0,0,UIntPtr.Zero);
mouse_event(MouseEventFlag.LeftUp,0,0,0,UIntPtr.Zero);
//这里是鼠标点击的代码(左键)
[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
}
[DllImport("user32.dll")]
static extern void mouse_event(MouseEventFlag flags, int dx, int dy, uint data, UIntPtr extraInfo);
在你的按钮单击事件中(Button_Click)加入如下代码:
Cursor.Position = new Point(0 /*x坐标*/, 0 /*y坐标*/); //这里是移动鼠标的代码
mouse_event(MouseEventFlag.LeftDown,0,0,0,UIntPtr.Zero);
mouse_event(MouseEventFlag.LeftUp,0,0,0,UIntPtr.Zero);
//这里是鼠标点击的代码(左键)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
using System;
using System.Collections.Generic;
using System.Text;
namespace MouseEvent
{
class Program
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
const int MOUSEEVENTF_MOVE = 0x0001;
const int MOUSEEVENTF_LEFTDOWN = 0x0002;
const int MOUSEEVENTF_LEFTUP = 0x0004;
const int MOUSEEVENTF_RIGHTDOWN = 0x0008;
const int MOUSEEVENTF_RIGHTUP = 0x0010;
const int MOUSEEVENTF_MIDDLEDOWN = 0x0020;
const int MOUSEEVENTF_MIDDLEUP = 0x0040;
const int MOUSEEVENTF_ABSOLUTE = 0x8000;
static void Main(string[] args)
{
for (int i = 0; i < 5; i++)
{
System.Threading.Thread.Sleep(1000);
//鼠标移动,坐标x,坐标y,只设置前三个参数就够了
mouse_event(MOUSEEVENTF_MOVE, 10, 0, 0, 0);
//鼠标左键点击
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
}
}
}
using System.Collections.Generic;
using System.Text;
namespace MouseEvent
{
class Program
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
const int MOUSEEVENTF_MOVE = 0x0001;
const int MOUSEEVENTF_LEFTDOWN = 0x0002;
const int MOUSEEVENTF_LEFTUP = 0x0004;
const int MOUSEEVENTF_RIGHTDOWN = 0x0008;
const int MOUSEEVENTF_RIGHTUP = 0x0010;
const int MOUSEEVENTF_MIDDLEDOWN = 0x0020;
const int MOUSEEVENTF_MIDDLEUP = 0x0040;
const int MOUSEEVENTF_ABSOLUTE = 0x8000;
static void Main(string[] args)
{
for (int i = 0; i < 5; i++)
{
System.Threading.Thread.Sleep(1000);
//鼠标移动,坐标x,坐标y,只设置前三个参数就够了
mouse_event(MOUSEEVENTF_MOVE, 10, 0, 0, 0);
//鼠标左键点击
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
获取鼠标点所在窗口的坐标或相对屏幕的坐标,然后你就可以做自己想做的了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询