Add ButtonEventHook

Hello nelson. I would like to ask you to add ButtonEventHook for key tracking.
If you are afraid that someone can find out someone else’s data. Why not disable key tracking when a player presses ESC and has the menu open. Or when he has the game inactive and also disable button tracking. This EventHook would be very useful for modding. And I think that many people will support me.
Here is a sample code.

using UnityEngine;
using UnityEngine.Events;

public class ButtonEventHook : MonoBehaviour
{
    [SerializeField] private KeyCode _key;

    [SerializeField] private UnityEvent _eventKeyDown;
    [SerializeField] private UnityEvent _eventKeyUp;
    [SerializeField] private UnityEvent _eventKeyPressed;

    private void Update()
    {
        if (Input.GetKeyDown(_key))
        {
            _eventKeyDown.Invoke();
        }

        if (Input.GetKeyUp(_key))
        {
            _eventKeyUp.Invoke();
        }

        if (Input.GetKey(_key))
        {
            _eventKeyPressed.Invoke();
        }
    }
}
1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.