Dec
13
2018

Adding Multiple Submit Keys to Input Manager

Had to make an UI button clickable by multiple different keyboard keys (like enter, space, left/right shift etc.)
And almost started writing custom script to handle extra keys when selecting UI button..

but then realized that you can duplicate Input Manager keys, and sure enough it works!
(see image above, you can right click to duplicate, then set new keys to it)

For the button i attached this init script, to make it selected (and highlighted) at start.
(otherwise user needs to select it manually first, before can click it, with controller for example)


using UnityEngine;
using UnityEngine.UI;
// makes button selected at Start (to force Highlighted color on it)
// this is required to allow pressing Fire / Submit key to press button (without having to select button first)
public class InitButton : MonoBehaviour
{
void Start ()
{
if (GetComponent<Button>())
{
GetComponent<Button>().Select();
Destroy(this);
}
}
}

view raw

InitButton.cs

hosted with ❤ by GitHub


Leave a comment

Connect

Twitter View LinkedIn profile Youtube Youtube Join Discord Twitch Instagram

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.