Exemplo n.º 1
0
        public static string ToLabel(this KeyboardKey key)
        {
            if (key.IsAcceptableInput())
            {
                return(key.ToChar().ToString());
            }
            else
            {
                switch (key)
                {
                case KeyboardKey.Backspace:
                    return("←");

                case KeyboardKey.Return:
                    return("return");

                default:
                    throw new System.Exception($"unexpected keycode {key}");
                }
            }
        }
Exemplo n.º 2
0
        public static char ToChar(this KeyboardKey key, bool uppercase = false)
        {
            if (!key.IsAcceptableInput(AcceptableKeyboardKeyFlags.Alphabetical | AcceptableKeyboardKeyFlags.Punctuation))
            {
                throw new Exception("given key is not alphabetical or punctuation");
            }

            switch (key)
            {
            case KeyboardKey.Space:
                return(' ');

            case KeyboardKey.Dash:
                return('-');

            case KeyboardKey.Apostrophe:
                return('\'');

            default:
                char chr = key.ToString()[0];
                return(uppercase ? chr : char.ToLower(chr));
            }
        }