1
0
mirror of https://github.com/xiaopeng12138/MaiDXR.git synced 2024-12-12 18:11:03 +01:00
MaiDXR/Assets/Scripts/ButtonToKey.cs

32 lines
942 B
C#
Raw Normal View History

2022-01-05 19:44:30 +01:00
using System;
using System.Runtime.InteropServices;
using UnityEngine;
public class ButtonToKey : MonoBehaviour
{
[DllImport("user32.dll")]
public static extern uint MapVirtualKey(uint uCode, uint uMapType);
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
public byte keyToPress;
2022-01-16 18:34:39 +01:00
//public Light lightTarget;
2022-01-05 19:44:30 +01:00
void Start()
{
2022-01-16 18:34:39 +01:00
//lightTarget.gameObject.SetActive(false);
2022-01-05 19:44:30 +01:00
}
2022-01-05 20:38:10 +01:00
private void OnTriggerEnter(Collider other)
2022-01-05 19:44:30 +01:00
{
keybd_event(System.Convert.ToByte(keyToPress), (byte)MapVirtualKey((uint)keyToPress, 0), 0, UIntPtr.Zero);
2022-01-16 18:34:39 +01:00
//lightTarget.gameObject.SetActive(true);
2022-01-05 19:44:30 +01:00
}
2022-01-05 20:38:10 +01:00
private void OnTriggerExit(Collider other)
2022-01-05 19:44:30 +01:00
{
keybd_event(System.Convert.ToByte(keyToPress), (byte)MapVirtualKey((uint)keyToPress, 0), 2, UIntPtr.Zero);
2022-01-16 18:34:39 +01:00
//lightTarget.gameObject.SetActive(false);
2022-01-05 19:44:30 +01:00
}
}