1
0
mirror of https://github.com/xiaopeng12138/MaiDXR.git synced 2025-02-22 04:59:29 +01:00
MaiDXR/Assets/Scripts/ButtonToKey.cs
2022-03-04 21:18:48 +01:00

28 lines
794 B
C#

using System;
using System.Runtime.InteropServices;
using UnityEngine;
using WindowsInput.Native;
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 VirtualKeyCode keyToPress;
void Start()
{
}
private void OnTriggerEnter(Collider other)
{
keybd_event(System.Convert.ToByte(keyToPress), (byte)MapVirtualKey((uint)keyToPress, 0), 0, UIntPtr.Zero);
}
private void OnTriggerExit(Collider other)
{
keybd_event(System.Convert.ToByte(keyToPress), (byte)MapVirtualKey((uint)keyToPress, 0), 2, UIntPtr.Zero);
}
}