unity3D基礎教程:自動打卡程式 類比滑鼠按鍵代碼

來源:互聯網
上載者:User
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;//這裡沒找到好的方法來延遲滑鼠按鍵,如果網頁開啟緩慢,可能會導致網頁還沒開啟,滑鼠已經類比按下.或者可以等待一定時間,個人感覺這種方法不好.還有就是每次開機時瀏覽器啟動的比較緩慢,也會導致滑鼠提前類比按下的情況

查看本欄目更多精彩內容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/extra/

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 ()  {        }        }

作者:csdn部落格 unity3d學習者

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.