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

42 lines
1.1 KiB
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 enum VirtualKeyCode;
public byte keyToPress;
public Light lightTarget;
public float frequency;
public float amplitude;
// Start is called before the first frame update
void Start()
{
lightTarget.gameObject.SetActive(false);
}
// Update is called once per frame
void Update()
{
}
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);
lightTarget.gameObject.SetActive(true);
}
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);
lightTarget.gameObject.SetActive(false);
}
}