2013-07-24
展开全部
你可以用Windows API的mouse_event函数来实现模拟鼠标的移动 代码如下 using System.Runtime.InteropServices; [DllImport("user32")]
private static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
private const int MOUSEEVENTF_MOVE = 0x0001;
private const int MOUSEEVENTF_ABSOLUTE = 0x8000;
private void button1_Click(object sender, EventArgs e)
{
//用一个Timer反复执行下面的代码就可以实现你要的效果
int width = Screen.PrimaryScreen.Bounds.Width;
int height = Screen.PrimaryScreen.Bounds.Height;
int offsetX = (MousePosition.X + 100) * 65535 / width;
int offsetY = (MousePosition.Y + 100) * 65535 / height;
mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, offsetX, offsetY, 0, 0);//相对当前位置移动100,100个像素
//mouse_event(MOUSEEVENTF_MOVE,1,1,0,0);//如果只是让鼠标动一下这么写就行
}
private static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
private const int MOUSEEVENTF_MOVE = 0x0001;
private const int MOUSEEVENTF_ABSOLUTE = 0x8000;
private void button1_Click(object sender, EventArgs e)
{
//用一个Timer反复执行下面的代码就可以实现你要的效果
int width = Screen.PrimaryScreen.Bounds.Width;
int height = Screen.PrimaryScreen.Bounds.Height;
int offsetX = (MousePosition.X + 100) * 65535 / width;
int offsetY = (MousePosition.Y + 100) * 65535 / height;
mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, offsetX, offsetY, 0, 0);//相对当前位置移动100,100个像素
//mouse_event(MOUSEEVENTF_MOVE,1,1,0,0);//如果只是让鼠标动一下这么写就行
}
推荐于2018-10-23
展开全部
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace WindowsApplication10
{
public partial class Form1 : Form
{
[DllImport("user32.dll")]
private static extern int SetCursorPos(int x, int y); public Form1()
{
InitializeComponent();
}
int i = 0; private void Form1_Load(object sender, EventArgs e)
{
timer1.Interval = 10000; } private void timer1_Tick(object sender, EventArgs e)
{
i = i + 3;
SetCursorPos(i, i);
}
}
}希望对你有所帮助。。。
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace WindowsApplication10
{
public partial class Form1 : Form
{
[DllImport("user32.dll")]
private static extern int SetCursorPos(int x, int y); public Form1()
{
InitializeComponent();
}
int i = 0; private void Form1_Load(object sender, EventArgs e)
{
timer1.Interval = 10000; } private void timer1_Tick(object sender, EventArgs e)
{
i = i + 3;
SetCursorPos(i, i);
}
}
}希望对你有所帮助。。。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询