Exemplo n.º 1
0
        private static string GetKeyDescription(KeyWithModifiers keys)
        {
            if (keys == null)
            {
                throw new ArgumentNullException("keys");
            }
            var keyScancodeDescriptionAttibute = Common.Generic.EnumAttributeReader.GetAttribute <F4KeyFile.DescriptionAttribute>((ScanCodes)keys.ScanCode);
            var keyScanCodeName = keyScancodeDescriptionAttibute != null ? keyScancodeDescriptionAttibute.Description: keys.ScanCode.ToString();
            var keyModifierDescriptionAttribute =
                Common.Generic.EnumAttributeReader.GetAttribute <F4KeyFile.DescriptionAttribute>(keys.Modifiers);

            var keyModifierNames = keyModifierDescriptionAttribute != null ? keyModifierDescriptionAttribute.Description: keys.Modifiers.ToString();

            if (keys.Modifiers != KeyModifiers.None && keys.ScanCode > 0)
            {
                return((keyModifierNames + " " + keyScanCodeName).ToUpper());
            }
            if (keys.Modifiers == KeyModifiers.None && keys.ScanCode > 0)
            {
                return(keyScanCodeName.ToUpper());
            }
            if (keys.Modifiers != KeyModifiers.None && keys.ScanCode <= 0)
            {
                return(keyModifierNames.ToUpper());
            }
            if (keys.Modifiers == KeyModifiers.None && keys.ScanCode <= 0)
            {
                return("");
            }
            return("");
        }
Exemplo n.º 2
0
        internal static char NormalizeKeyChar(this ConsoleKeyInfo key)
        {
            if (key.KeyChar == '\0' && (key.Modifiers & ConsoleModifiers.Control) != 0)
            {
                if (key.Key >= ConsoleKey.A && key.Key <= ConsoleKey.Z)
                {
                    return((char)(key.Key - ConsoleKey.A + 1));
                }

                int d = key.Key >= ConsoleKey.D0 && key.Key <= ConsoleKey.D9
                    ? key.Key - ConsoleKey.D0
                    : key.Key >= ConsoleKey.NumPad0 && key.Key <= ConsoleKey.NumPad9
                        ? key.Key - ConsoleKey.NumPad0
                        : -1;

                switch (d)
                {
                case 2: return('\0');

                case 6: return('\x1e');

                case 0:
                case 1:
                case 3:
                case 4:
                case 5:
                case 7:
                case 8:
                case 9:
                    return((char)('0' + d));
                }

                // On Windows, ConsoleKeyInfo.Key is something we wanted to ignore, but
                // a few bindings force us to do something with it.
                var mods        = key.Modifiers & ConsoleModifiers.Shift;
                var keyWithMods = new KeyWithModifiers(key.Key, mods);
                if (CtrlKeyToKeyCharMap != null && CtrlKeyToKeyCharMap.TryGetValue(keyWithMods, out var keyChar))
                {
                    return(keyChar);
                }
            }
            return(key.KeyChar);
        }
Exemplo n.º 3
0
        static Keys()
        {
            int i;

            for (i = 0; i < 26; i++)
            {
                CtrlKeyToKeyCharMap.Add(new KeyWithModifiers(ConsoleKey.A + i), (char)(i + 1));
            }

            for (i = 0; i < 10; i++)
            {
                char c = i == 2 ? '\0' : i == 6 ? '\x1e' : (char)('0' + i);
                CtrlKeyToKeyCharMap.Add(new KeyWithModifiers(ConsoleKey.D0 + i), c);
                CtrlKeyToKeyCharMap.Add(new KeyWithModifiers(ConsoleKey.NumPad0 + i), c);
            }

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                // These mapping are needed to support different keyboard
                // layouts, e.g. ']' is Oem6 with an English keyboard, but
                // Oem5 with a Portuguese keyboard.
                foreach (char c in "`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/?")
                {
                    var scan = VkKeyScan((short)c);
                    ConsoleModifiers mods = 0;
                    if ((scan & 0x100) != 0)
                    {
                        mods |= ConsoleModifiers.Shift;
                    }
                    if ((scan & 0x200) != 0)
                    {
                        mods |= ConsoleModifiers.Control;
                    }
                    if ((scan & 0x400) != 0)
                    {
                        mods |= ConsoleModifiers.Alt;
                    }
                    var key = new KeyWithModifiers((ConsoleKey)(scan & 0xff), mods);
                    CtrlKeyToKeyCharMap.Add(key, c);
                }
            }
        }
Exemplo n.º 4
0
        internal static char NormalizeKeyChar(this ConsoleKeyInfo key)
        {
            if (key.KeyChar == '\0' && (key.Modifiers & ConsoleModifiers.Control) != 0)
            {
                // On Windows, ConsoleKeyInfo.Key is something we wanted to ignore, but
                // a few bindings force us to do something with it.
                var mods        = key.Modifiers & ConsoleModifiers.Shift;
                var keyWithMods = new KeyWithModifiers(key.Key, mods);
                if (CtrlKeyToKeyCharMap.TryGetValue(keyWithMods, out var keyChar))
                {
                    return(keyChar);
                }

                if (key.Key >= ConsoleKey.A && key.Key <= ConsoleKey.Z)
                {
                    return((char)(key.Key - ConsoleKey.A + 1));
                }
            }
            return(key.KeyChar);
        }
Exemplo n.º 5
0
 private void Dispose(bool disposing)
 {
     if (!_isDisposed)
     {
         if (disposing)
         {
             //dispose of managed resources here
             Common.Util.DisposeObject(_keyFile);
             _keyFile = null;
             Common.Util.DisposeObject(_sharedMemReader);
             _sharedMemReader = null;
             Common.Util.DisposeObject(_texSharedMemReader);
             _texSharedMemReader = null;
             Common.Util.DisposeObject(_pendingComboKeys);
             _pendingComboKeys = null;
             Common.Util.DisposeObject(_terrainDB);
             _terrainDB = null;
         }
     }
     // Code to dispose the un-managed resources of the class
     _isDisposed = true;
 }