How can I access an input style in the Other section of the Input list via script?

Hi, I am trying to work with the Keijiro Minis MIDI input system that you can read about here GitHub - keijiro/Minis: Minis: MIDI Input for New Input System -- A plugin that adds MIDI input support to Unity's new Input System. And in my input manager, the MIDI interface is all set up, and one could find it in the other section of all of the inputs when one would look at it in a list. But, how can I get ahold of that path or that input style in script so that I can have it invoke an onclick action of a button? in the manner of a public button being listed and then an if statement saying Input.SoOnandSoForth… etc. Does anyone know how I can do this or is this to be done in a more complex way?

I tried this based off of the script that played the animation via MIDI in the project file that the plugin is imported in, but of course it is not a button that it is invoking so I am trying to figure out the method to do so.

using System.Collections;
using System.Collections.Generic;
using JetBrains.Annotations;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Playables;
using UnityEngine.UI;


   
    sealed class MIDIAssignScript : MonoBehaviour
    {
        [SerializeField] PlayableDirector _playable = null;
        [SerializeField] InputAction _action = null;
        [SerializeField] Button A1;

        void OnEnable()
        {
            _action.performed += OnPerformed;
       
            _action.Enable();
        }

        void OnDisable()
        {
            _action.performed -= OnPerformed;
            _action.Disable();
        }

        void OnPerformed(InputAction.CallbackContext ctx)
            => A1.onClick.Invoke();

    }

This was the original script that played the animation via MIDI input

using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Playables;

sealed class PlayByInputAction : MonoBehaviour
{
    [SerializeField] PlayableDirector _playable = null;
    [SerializeField] InputAction _action = null;

    void OnEnable()
    {
        _action.performed += OnPerformed;
       
        _action.Enable();
    }

    void OnDisable()
    {
        _action.performed -= OnPerformed;
        _action.Disable();
    }

    void OnPerformed(InputAction.CallbackContext ctx)
      => _playable.Play();
}

I tried adding an Input Action Asset with a test for the A1 key, and named it A1 and put it on the script on the panel of the scene that I was trying to use to invoke the A1 button with the A1 key but it still did not work. I thought maybe it would. Here is the script.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class MIDI_InputTest : MonoBehaviour
{
    public Button A1;

    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("A1"))
        {
            A1.onClick.Invoke();
        }
    }
}

I tried GetKeyDown instead of GetButtonDown and that did not work either.

That’s the old input system. It has no relation to the new input system and they do not interoperate at all. So this is never going to work.

You don’t want your input to activate a button, you want the button and your input to both initiate the same thing. Just point the both of them at the same method that does the necessary action.

Well, that seems difficult because the button has to highlight at the very least and serve as the correct answer out of 88 keys. Because the button gives one point, plays a wav sound, and shuffles to the next scene along with high light on click. I just dont see how I can do it any other way than to some how have the input invoke a button click some how.

Sorry, are you making some kind of typing/music game? Do you need to know which particular key is being pressed?

Yes, so it is a sight reading educational software for the piano that I am constantly trying to improve and just got up and launched. I will DM you the link to the website if you want to have a look at it, you have helped me out so much in all of these forums it seems only right. But, that is definitely the case. It is an 88 key piano map that gives correct and incorrect scores.

I really am just looking for a proper explanation of your problem.

If you want to listen for arbitrary key presses you can look at this: Class InputSystem | Input System | 1.8.2

You will want to separate the visual input (the UI buttons) and the physical input from what keys you’re expecting to be pressed as well. You don’t want your input to be calling UI buttons as there’s no reason to have that dependency. Both can just be calling the same system.

I know but the button key on the screen will not highlight if the input does not invoke the button. You can see the gameplay trailer for it on the purchase page to see what I am talking about. I am sure this is possible, I have tried different names that it should reference by as it is in the input manager, but nothing has worked so far.

It’s entirely possible the way I described but I won’t go there as it’s probably out of your depth.

Looking at your code above I can see that the problem is that you’re serialising an InputAction. You should not use this class directly. It’s meant to be a part of a greater input action map.

If you want an input action you can reference via the inspector, use InputActionReference instead. These are the scriptable object sub-objects that get generated as part of your InputActionAsset.

If you want to do it via the buttons, then you will need to make an input action for every UI button. Said button will need to reference their respective input action reference, and then you can hook into both of them to get the right callbacks.

So, I looked into that and it was a bit confusing, but I found this and it seems like it could be what does the trick, but I cannot figure out why my a few of my bottom brackets have little red errors on them that says “;” is expected. And when I add the semi colon it does not fix the last bracket on the script, it still leaves it as incorrect.

using System;
using System.Collections;
using System.Collections.Generic;
using Minis;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;



public class MIDI_InputTest : MonoBehaviour
{
    public Button A1Button;

    [SerializeField] private InputActionReference A1Ref;
    [SerializeField] private InputActionAsset MIDI_Controls;

    private void Awake()
    {
      
    }

    private void Start()
    {
        InputSystem.onDeviceChange += (device, change) => {
            var midiDevice = device as Minis.MidiDevice;
            if (midiDevice == null) return;
  
            midiDevice.onWillNoteOn += (note, velocity) => {
      
                // When middle C (MIDI #60) is pressed:
                if (note.noteNumber == 60) {
          
                    A1Button.onClick.Invoke();
                }
            }
  
          
            }
        }
    }

  
}

Okay, I had an unexpected token, and I got it to invoke the button click, but it did not run the on click high light button function. But, that is progress certainly.

I tried this, but it did not work, I am thinking it has to be something along these lines.

A1Button.interactable.HasProperty("Pressed");

None of that code makes sense honestly, and for some reason you decided to mash together both my suggestions? One or the other, not both. You’re not even using the referenced assets?