Using Unityengine;
Using System.Collections;
Using System.Diagnostics;
public class Newbehaviourscript1:monobehaviour {
[System.Runtime.InteropServices.DllImport ("user32")]//import user32 This DLL file, in fact, we use the analog mouse button has been encapsulated in this Windows file.
private static extern int mouse_event (int dwflags, int dx, int dy, int cbuttons, int dwextrainfo); Referencing the methods in User32.dll, the following are the same:
Unity3d Learning Tutorial Automatic clocking program simulate mouse button code
[System.Runtime.InteropServices.DllImport ("user32")]
private static extern bool Setcursorpos (int x, int y);
const int mouseeventf_move = 0x0001; Defines the mouse state
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;//There is no good way to delay the mouse button, if the page is slow to open, may cause the Web page has not been opened, the mouse has been simulated press. Or can wait for a certain time, personal feeling this method is not good. And that is, every time the browser starts up slowly, can also cause the mouse to simulate the pressed situation in advance
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/extra/
int x=1120;//The position of the clocking button, the computer resolution is different, may cause the position also different, this according to the actual situation fine-tuning:
int y=370;
Setcursorpos (x,y)//Set mouse position
mouse_event (mouseeventf_leftdown,0, 0, 0, 0);////simulate mouse down, bounce
mouse_event ( Mouseeventf_leftup, 0, 0, 0, 0);
Update is called once per frame
void Update ()
}
Author: csdn Blog Unity3d Learner