// Gets a UnityEngine.KeyCode from a string
public static KeyCode StringToKeycode(string keyCodeStr)
{
if(!string.IsNullOrEmpty(keyCodeStr)) // Empty strings are automatically invalid
{
try
{
// Case-insensitive parse of UnityEngine.KeyCode to check if string is valid
KeyCode keyCode = (KeyCode)Enum.Parse(typeof(KeyCode), keyCodeStr, true);
return keyCode;
}
catch { }
}
return KeyCode.Delete; // If string is invalid, return Delete as the default key
}