看這篇文章之前建議先看 移動滑鼠這篇:http://lolikitty.pixnet.net/blog/post/164570070

using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;

public class MouseControl : MonoBehaviour
{

    [DllImport("user32")]
    static extern bool SetCursorPos (int X, int Y);

    [DllImport("user32")]
    static extern void mouse_event (int dwFlags);

    enum MouseEventFlag
    {
        Move = 0x0001, // 移動
        LeftDown = 0x0002, // 按下滑鼠左鍵
        LeftUp = 0x0004, // 放開滑鼠左鍵
        RightDown = 0x0008, // 按下滑鼠右鍵
        RightUp = 0x0010, // 放開滑鼠右鍵
        MiddleDown = 0x0020, // 按下滑鼠中鍵
        MiddleUp = 0x0040, // 放開滑鼠中鍵
        XDown = 0x0080, // 往下
        XUp = 0x0100, // 往上
        Wheel = 0x0800, // 滑鼠滾輪
        VirtualDesk = 0x4000, // 虛擬桌面
        Absolute = 0x8000 // 獨立鍵
    }

    void ClickLeft(){ // 點擊滑鼠左鍵
        mouse_event ((int)MouseEventFlag.LeftDown); // 模擬按下滑鼠左鍵
        mouse_event ((int)MouseEventFlag.LeftUp); // 模擬放開滑鼠左鍵
    }

    void ClickRight(){ // 點擊滑鼠右鍵
        mouse_event ((int)MouseEventFlag.RightDown); // 模擬按下滑鼠右鍵
        mouse_event ((int)MouseEventFlag.RightUp); // 模擬放開滑鼠
    }

    void Start ()
    {
        SetCursorPos (0, 0); // 將滑鼠移動到 x = 0 , y = 0 的位置 (螢幕左上角)
        Time.fixedDeltaTime = 1.0F; // 設定底下的 FixedUpdate () 方法每 1 秒執行一次
    }

    void FixedUpdate () // 每秒點擊滑鼠左鍵
    {
        ClickLeft(); // 點擊滑鼠左鍵
    }
}

 

 

 

Magical Charming! 応援中!

 

arrow
arrow
    全站熱搜

    黃彥霖 發表在 痞客邦 留言(0) 人氣()