Unity3d Basic Tutorial: Auto-clocking program simulation mouse button code

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.