鼠标在屏幕上乱跳

using System;
using System.Windows.Forms;//添加下引用
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Runtime.InteropServices;

/*windows API的调用*/


namespace monse_click
{
class Program
{ [DllImportAttribute("user32.dll",EntryPoint="SetCursorPos")]//setcurso在user32.dll里面,要用DLLimport需要有runtime.interservices命名空间,接口调用
public static extern bool SetCursorPos(int x,int y);//要在里面调用,则需要声明下
/* setcursorpos函数,里面两个变量标出了光标的坐标*/

static void Main(string[] args)
{
Random t = new Random();
int i = 0;
while (i < 10)
{
System.Drawing.Rectangle rece = Screen.PrimaryScreen.Bounds;
int x = t.Next(0, rece.Width);
int y = t.Next(0, rece.Height);
SetCursorPos(x, y);
i++;
Thread.Sleep(3000);//创建一个线程来执行这个操作,3000MS即5S中执行一次循环
}
Console.ReadKey();

}
}
}
posted @ 2012-02-04 13:36  RINA  阅读(434)  评论(0编辑  收藏  举报