Unity 시 뮬 레이 션 마우스 자동 클릭 이벤트
2489 단어 Unity
마우스 클릭 이벤트 가 자동 으로 호출 되 어야 할 때 가 있 습 니 다.아래 는 수 요 를 만족 시 킬 수 있 습 니 다.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
public class ImitateMouseClick : MonoBehaviour {
///
///
///
///
/// x (0~65535)
/// y (0~65535)
/// (120 )
///
[DllImport("user32.dll")]
static extern void mouse_event(MouseEventFlag flags, int dx, int dy, uint data, UIntPtr extraInfo);
///
///
///
[Flags]
enum MouseEventFlag : uint
{
Move = 0x0001,
LeftDown = 0x0002,
LeftUp = 0x0004,
RightDown = 0x0008,
RightUp = 0x0010,
MiddleDown = 0x0020,
MiddleUp = 0x0040,
XDown = 0x0080,
XUp = 0x0100,
Wheel = 0x0800,
VirtualDesk = 0x4000,
///
/// (dx,dy),
///
Absolute = 0x8000
}
void Update()
{
if(Input.GetKeyDown(KeyCode.A))
{
Debug.Log(" A Down");
DoMouseClick(600, 800);
}
if(Input.GetMouseButtonDown(0))
{
Debug.Log(" Down ");
}
if (Input.GetMouseButtonUp(0))
{
Debug.Log(" Up ");
}
}
///
/// ( x,y )
///
/// X
/// Y
private static void DoMouseClick(int x, int y)
{
int dx = (int)((double)x / Screen.width * 65535); // 0~65535(0xffff, 16 )
int dy = (int)((double)y / Screen.height * 0xffff); // double , 0、1
mouse_event(MouseEventFlag.Move | MouseEventFlag.LeftDown | MouseEventFlag.LeftUp | MouseEventFlag.Absolute, dx, dy, 0, new UIntPtr(0)); //
}
}
주의:Mouse EventFlag.Absolute 를 잘 이용 하여 위 치 를 정 해 야 합 니 다.
mouse_event(MouseEventFlag.LeftDown| MouseEventFlag.Absolute, dx, dy, 0, new UIntPtr(0)); //
이것 은 상대 적 으로 왼쪽 상단 의 위치 이다.
DoMouseClick(600, 800);
4.567913.이것 은 현재 마우스 의 위치 입 니 다.이것 은 자동 으로 마우스 클릭 단 추 를 호출 할 수 있 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
photonnetwork.instantiate에서 gamepobject 유형을 생성 한 다음 상태 및 값을 참조하는 방법주로 마지막 기사에서 일어난 일의 수정입니다. 지난번↓ 그럼 주제입니다. (타이틀이 정리되어 없어서 죄송합니다) 우선 전회의 Illegal view ID:0입니다만 photonnetwork.instantiate를 사...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.