php模拟鼠标,自动打卡程序 模拟鼠标按键代码【unity3D基础教程】

using UnityEngine;

using System.Collections;

using System.Diagnostics;

public class NewBehaviourScript1 : MonoBehaviour {

[System.Runtime.InteropServices.DllImport("user32")]//导入user32这个dll文件,其实我们用到的模拟鼠标按键已经封装在这个windows下的文件里了

private static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); //引用user32.dll中的方法,下面同理:

unity3d学习教程  自动打卡程序 模拟鼠标按键代码

[System.Runtime.InteropServices.DllImport("user32")]

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

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;

// Use this for initialization

void Start ()

{

StartCoroutine(OpenWs());

}

IEnumerator OpenWs()

{

Process.Start("http://www.unitymanual.com/u.php");

WWW web=new WWW("http://www.unitymanual.com/u.php");

yield return web;//这里没找到好的方法来延迟鼠标按键,如果网页打开缓慢,可能会导致网页还没打开,鼠标已经模拟按下.或者可以等待一定时间,个人感觉这种方法不好.还有就是每次开机时浏览器启动的比较缓慢,也会导致鼠标提前模拟按下的情况

int x=1120;//打卡按钮的位置,电脑分辨率不同,可能导致位置也不同,这个根据实际情况微调下:

int y=370;

SetCursorPos(x,y);//设置鼠标位置

mouse_event(MOUSEEVENTF_LEFTDOWN,0, 0, 0, 0); //模拟鼠标按下,弹起

mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

}

// Update is called once per frame

void Update ()

{

}

}

本文由

unity3d学习者 收集整理,仅供大家学习参考。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值