private void AssertMapping(KeyState keyState, string text, KeyModifiers modifiers = KeyModifiers.None)
 {
     VimKeyData vimKeyData;
     Assert.True(_keyStateToVimKeyDataMap.TryGetValue(keyState, out vimKeyData));
     Assert.Equal(text, vimKeyData.TextOptional);
     Assert.Equal(modifiers, vimKeyData.KeyInputOptional.KeyModifiers);
 }
Esempio n. 2
0
        private bool TryGetKeyInput(Key key, ModifierKeys modifierKeys, out VimKeyData vimKeyData)
        {
            var virtualKeyModifiers = KeyState.GetVirtualKeyModifiers(modifierKeys);
            if (_virtualKeyboard.UsesExtendedModifiers)
            {
                virtualKeyModifiers |= _virtualKeyboard.VirtualKeyModifiersExtended;
            }

            if (_virtualKeyboard.IsCapsLockToggled)
            {
                virtualKeyModifiers |= VirtualKeyModifiers.CapsLock;
            }

            // First just check and see if there is a direct mapping
            var keyState = new KeyState(key, virtualKeyModifiers);
            if (_keyStateToVimKeyDataMap.TryGetValue(keyState, out vimKeyData))
            {
                return true;
            }

            // Next consider only the shift key part of the requested modifier.  We can
            // re-apply the original modifiers later
            keyState = new KeyState(key, virtualKeyModifiers & VirtualKeyModifiers.Shift);
            if (_keyStateToVimKeyDataMap.TryGetValue(keyState, out vimKeyData) &&
                vimKeyData.KeyInputOptional != null)
            {
                // Reapply the modifiers
                var keyInput = KeyInputUtil.ApplyModifiers(vimKeyData.KeyInputOptional, ConvertToKeyModifiers(modifierKeys));
                vimKeyData = new VimKeyData(keyInput, vimKeyData.TextOptional);
                return true;
            }

            // Last consider it without any modifiers and reapply
            keyState = new KeyState(key, VirtualKeyModifiers.None);
            if (_keyStateToVimKeyDataMap.TryGetValue(keyState, out vimKeyData) &&
                vimKeyData.KeyInputOptional != null)
            {
                // Reapply the modifiers
                var keyInput = KeyInputUtil.ApplyModifiers(vimKeyData.KeyInputOptional, ConvertToKeyModifiers(modifierKeys));
                vimKeyData = new VimKeyData(keyInput, vimKeyData.TextOptional);
                return true;
            }

            return false;
        }
Esempio n. 3
0
        /// <summary>
        /// Is the specified key information a dead key
        /// </summary>
        internal bool IsDeadKey(Key key, ModifierKeys modifierKeys)
        {
            var keyState = new KeyState(key, modifierKeys);
            VimKeyData vimKeyData;
            if (!_keyStateToVimKeyDataMap.TryGetValue(keyState, out vimKeyData))
            {
                return false;
            }

            return vimKeyData.IsDeadKey;
        }
            public void ControlWithAlpha()
            {
                Create();
                foreach (var cur in CharLettersLower)
                {
                    var key = (Key)Enum.Parse(typeof(Key), Char.ToUpper(cur).ToString());
                    var keyState = new KeyState(key, ModifierKeys.Control);

                    VimKeyData vimKeyData;
                    Assert.True(_keyStateToVimKeyDataMap.TryGetValue(keyState, out vimKeyData));
                    Assert.Equal(KeyInputUtil.CharWithControlToKeyInput(cur), vimKeyData.KeyInputOptional);
                }
            }
Esempio n. 5
0
        /// <summary>
        /// Build up the set of dead keys in this keyboard layout
        /// </summary>
        private void BuildRemainingData(Dictionary<char, KeyInput> map)
        {
            var shiftStateModifiers = GetShiftStateModifiers();
            foreach (Key key in Enum.GetValues(typeof(Key)))
            {
                foreach (var shiftStateModifier in shiftStateModifiers)
                {
                    var virtualKey = (uint)KeyInterop.VirtualKeyFromKey(key);
                    var keyState = new KeyState(key, shiftStateModifier);

                    // This will be true for the special vim keys which we map directly by virtual
                    // key.  For instance the KeypadMultiply is already mapped to VK_MULTIPLY.  Yet
                    // it has the same text a Shift+8 on a QWERTY keyboard.  This means that two
                    // vim key combinations map to the same character (in this case *).  Don't overwrite
                    // the original mapping
                    if (_keyStateToVimKeyDataMap.ContainsKey(keyState))
                    {
                        continue;
                    }

                    bool isDeadKey;
                    string text;
                    if (_virtualKeyboard.TryGetText(virtualKey, shiftStateModifier, out text, out isDeadKey))
                    {
                        KeyInput keyInput;
                        if (text.Length == 1 && map.TryGetValue(text[0], out keyInput))
                        {
                            AddMapping(keyState, keyInput, text);
                        }
                    }
                    else if (isDeadKey)
                    {
                        keyState = new KeyState(key, VirtualKeyModifiers.None);
                        _keyStateToVimKeyDataMap[keyState] = VimKeyData.DeadKey;
                    }
                }
            }
        }
Esempio n. 6
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;
            }
        }
Esempio n. 7
0
        private void AddMapping(KeyState keyState, KeyInput keyInput, string text)
        {
            _keyStateToVimKeyDataMap[keyState] = new VimKeyData(keyInput, text);

            FrugalList<KeyState> list;
            if (!_keyInputToWpfKeyDataMap.TryGetValue(keyInput, out list))
            {
                _keyInputToWpfKeyDataMap[keyInput] = new FrugalList<KeyState>(keyState);
            }
            else
            {
                list.Add(keyState);
            }
        }
Esempio n. 8
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);

                // Need to consider alternate keys here because they are often mapped differently than the
                // primary key.  Consider CTRL-H and <BS> for example.  CTRL-H is mapped by the character
                // code 0x8 while <BS> is mapped by VK_BACK.  Need to build up both mappings here
                var alternateKeyInput = KeyInputUtil.GetAlternate(current);
                if (alternateKeyInput.IsSome())
                {
                    BuildKeyInputData(map, alternateKeyInput.Value);
                }
            }
            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;
            }
        }