Skip to content

KeyCode Parse #1

Description

@abobanamne
// 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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions