Esempio n. 1
0
        private bool TryConvert(KeyInput keyInput, out Key key, out ModifierKeys modifierKeys)
        {
            if (AlternateKeyUtil.TrySpecialVimKeyToKey(keyInput.Key, out key))
            {
                var keyModifiers = keyInput.KeyModifiers;

                modifierKeys = ModifierKeys.None;
                if (KeyModifiers.Control == (keyModifiers & KeyModifiers.Control))
                {
                    modifierKeys |= ModifierKeys.Control;
                }

                if (KeyModifiers.Shift == (keyModifiers & KeyModifiers.Shift))
                {
                    modifierKeys |= ModifierKeys.Shift;
                }

                if (KeyModifiers.Alt == (keyModifiers & KeyModifiers.Alt))
                {
                    modifierKeys |= ModifierKeys.Alt;
                }

                return(true);
            }

            if (keyInput.RawChar.IsSome())
            {
                uint virtualKey;
                VirtualKeyModifiers virtualKeyModifiers;

                if (_virtualKeyboard.TryMapChar(keyInput.Char, out virtualKey, out virtualKeyModifiers))
                {
                    key          = KeyInterop.KeyFromVirtualKey((int)virtualKey);
                    modifierKeys = ModifierKeys.None;

                    if (VirtualKeyModifiers.Control == (virtualKeyModifiers & VirtualKeyModifiers.Control))
                    {
                        modifierKeys |= ModifierKeys.Control;
                    }

                    if (VirtualKeyModifiers.Shift == (virtualKeyModifiers & VirtualKeyModifiers.Shift))
                    {
                        modifierKeys |= ModifierKeys.Shift;
                    }

                    if (VirtualKeyModifiers.Alt == (virtualKeyModifiers & VirtualKeyModifiers.Alt))
                    {
                        modifierKeys |= ModifierKeys.Alt;
                    }

                    return(true);
                }
            }

            key          = Key.None;
            modifierKeys = ModifierKeys.None;
            return(false);
        }
Esempio n. 2
0
        private void BuildKeyInputData(Dictionary <char, KeyInput> map, KeyInput current)
        {
            if (current.Key == VimKey.Nop)
            {
                return;
            }

            uint virtualKey;

            if (TrySpecialVimKeyToVirtualKey(current.Key, out virtualKey))
            {
                // This is a key for which we do direct virtual key mapping.  Add it to the final
                // map now.  It's not depnedent upon the character that is generated by a given
                // key stroke as are many of the items
                var key = KeyInterop.KeyFromVirtualKey((int)virtualKey);
                if (Key.None == key)
                {
                    return;
                }

                var text = current.RawChar.IsSome()
                    ? current.Char.ToString()
                    : String.Empty;
                var keyState = new KeyState(key, ModifierKeys.None);
                AddMapping(keyState, current, text);
            }
            else
            {
                // At this point we should have a char for all of the other inputs
                Debug.Assert(current.RawChar.IsSome());
                Debug.Assert(!map.ContainsKey(current.Char));
                Debug.Assert(current.KeyModifiers == KeyModifiers.None || current.KeyModifiers == KeyModifiers.Control);

                // Do a quick check to see if we have an extended shift state modifier in our midst.
                VirtualKeyModifiers virtualKeyModifiers;
                if (_virtualKeyboard.TryMapChar(current.Char, out virtualKey, out virtualKeyModifiers) &&
                    0 != (virtualKeyModifiers & VirtualKeyModifiers.Extended))
                {
                    LookForOemModifiers(current.Char, virtualKey, virtualKeyModifiers);
                }

                map[current.Char] = current;
            }
        }