예제 #1
0
        protected override string GetReadableKey(InputKey key)
        {
            var keycode = SDL.SDL_GetKeyFromScancode(key.ToScancode());

            // early return if unknown. probably because key isn't a keyboard key, or doesn't map to an `SDL_Scancode`.
            if (keycode == SDL.SDL_Keycode.SDLK_UNKNOWN)
            {
                return(base.GetReadableKey(key));
            }

            string name;

            // overrides for some keys that we want displayed differently from SDL_GetKeyName().
            if (TryGetNameFromKeycode(keycode, out name))
            {
                return(name);
            }

            name = SDL.SDL_GetKeyName(keycode);

            // fall back if SDL couldn't find a name.
            if (string.IsNullOrEmpty(name))
            {
                return(base.GetReadableKey(key));
            }

            // true if SDL_GetKeyName() returned a proper key/scancode name.
            // see https://github.com/libsdl-org/SDL/blob/release-2.0.16/src/events/SDL_keyboard.c#L1012
            if (((int)keycode & SDL.SDLK_SCANCODE_MASK) != 0)
            {
                return(name);
            }

            // SDL_GetKeyName() returned a unicode character that would be produced if that key was pressed.
            // consumers expect an uppercase letter.
            return(name.ToUpper());
        }