/// <summary>
        /// Is this an advanced key stroke like CTRL+V which we don't want to automatically
        /// convert.
        /// </summary>
        private bool IsAdvanced(KeyStroke keyStroke)
        {
            // Look for paste
            if (keyStroke.KeyModifiers == KeyModifiers.Control &&
                keyStroke.KeyInput.Key == VimKey.LowerV &&
                keyStroke.KeyInput.KeyModifiers == KeyModifiers.None)
            {
                return(true);
            }

            // Look for cut
            if (keyStroke.KeyModifiers == KeyModifiers.Control &&
                keyStroke.KeyInput.Key == VimKey.LowerX &&
                keyStroke.KeyInput.KeyModifiers == KeyModifiers.None)
            {
                return(true);
            }

            // Look for select all
            if (keyStroke.KeyModifiers == KeyModifiers.Control &&
                keyStroke.KeyInput.Key == VimKey.LowerA &&
                keyStroke.KeyInput.KeyModifiers == KeyModifiers.None)
            {
                return(true);
            }

            return(false);
        }
        private static void AddKeyStrokeData(KeyStroke keyStroke, IEnumerable <ComparisonUnit> comparisonUnits, TrackedDocuments trackedDocuments)
        {
            // identify the starting position of content, added, removed or replaced.
            keyStroke.Text     = GetTypedText(comparisonUnits);
            keyStroke.Position = Convert.ToInt32(GetTargetCursorPosition());
            keyStroke.X        = Cursor.Position.X;
            keyStroke.Y        = Cursor.Position.Y;

            // needs to be revised!
            // 1. exclude translations from providers
            // 2. exclude suggestions from termbase? no api handler here...
            // 3. if content that has changed is greater than 1 char in length, then evaluate
            //  - 3.a. if the char == tab or return, then we assume that this was derived from auto-suggest; however
            //         this does not take into account when the user has selected the auto-suggestion via mouse etc...
            if (string.Compare(keyStroke.Key, @"[Tab]", StringComparison.OrdinalIgnoreCase) == 0 && keyStroke.Text.Length > 1)
            {
                keyStroke.OriginType = @"auto-suggest";
            }

            //if the user hit the back key then attempt to get the selection from the comparison if it is not already present
            if (string.IsNullOrEmpty(keyStroke.Selection))
            {
                keyStroke.Selection = GetSelectedText(comparisonUnits);
            }

            if (string.IsNullOrEmpty(keyStroke.Text) && string.IsNullOrEmpty(keyStroke.Selection))
            {
                return;
            }

            //add the key stroke object to the list
            trackedDocuments.ActiveSegment.CurrentTranslationKeyStokeObjectId     = keyStroke.Id;
            trackedDocuments.ActiveSegment.CurrentTranslationKeyStrokeObjectCheck = true;
            trackedDocuments.ActiveSegment.CurrentKeyStrokes.Add(keyStroke);
        }
예제 #3
0
        public bool Consume(KeyEventArgs args)
        {
            var          repeat = args.EventType == KeyEventType.KeyRepeat;
            var          stroke = new KeyStroke(args);
            RepeatAction action;

            if (keyboardActionMap.TryGetValue(stroke, out action))
            {
                if (!repeat || action.AllowRepeat)
                {
                    action.Action(args);
                }
                return(true);
            }

            foreach (var source in keyboardActionMap)
            {
                if (stroke.IsMatchForAction(source.Key))
                {
                    if (!repeat || source.Value.AllowRepeat)
                    {
                        source.Value.Action(args);
                    }
                    return(true);
                }
            }
            return(false);
        }
        public KeyStroke?ParseStroke(string keyString, CultureInfo?culture = null)
        {
            string       keys      = keyString;
            ModifierKeys modifiers = ModifierKeys.None;

            for (int plusIndex = keyString.IndexOf('+');
                 plusIndex >= 0 && plusIndex < keyString.Length;
                 plusIndex = keyString.IndexOf('+', plusIndex + 1))
            {
                string modifiersSubstring = keyString.Substring(0, plusIndex);
                if (this.modifierConverter.IsValid(modifiersSubstring))
                {
                    modifiers = (ModifierKeys)this.modifierConverter.ConvertFromString(null, culture, modifiersSubstring);
                    keys      = keyString.Substring(plusIndex + 1);
                }
                else
                {
                    break;
                }
            }
            var stroke = new KeyStroke {
                Modifiers = modifiers
            };

            foreach (string key in keys.Split('+'))
            {
                if (!this.keyConverter.IsValid(key))
                {
                    return(null);
                }
                stroke.Keys.Add((Key)this.keyConverter.ConvertFromString(null, culture, key));
            }
            return(stroke);
        }
예제 #5
0
        static Viewer()
        {
            LastKeyWasLetter = false;

            IsTracking = true;
            KsCache    = new KeyStroke();
        }
예제 #6
0
        private static void AddKeyStrokeData(KeyStroke keyStroke, string typedText, string removedText, int position, TrackedDocuments trackedDocuments)
        {
            keyStroke.Text     = typedText;
            keyStroke.Position = position;
            keyStroke.X        = Cursor.Position.X;
            keyStroke.Y        = Cursor.Position.Y;

            // needs to be revised!
            // 1. exclude translations from providers
            // 2. exclude suggestions from termbase? no api handler here...
            // 3. if content that has changed is greater than 1 char in length, then evaluate
            //  - 3.a. if the char == tab or return, then we assume that this was derived from auto-suggest; however
            //         this does not take into account when the user has selected the auto-suggestion via mouse etc...
            if (string.Compare(keyStroke.Key, @"[Tab]", StringComparison.OrdinalIgnoreCase) == 0 && keyStroke.Text.Length > 1)
            {
                keyStroke.OriginType = @"auto-suggest";
            }

            keyStroke.Selection = removedText;

            if (string.IsNullOrEmpty(keyStroke.Text) && string.IsNullOrEmpty(keyStroke.Selection))
            {
                return;
            }

            //add the key stroke object to the list
            trackedDocuments.ActiveSegment.CurrentTranslationKeyStokeObjectId     = keyStroke.Id;
            trackedDocuments.ActiveSegment.CurrentTranslationKeyStrokeObjectCheck = true;
            trackedDocuments.ActiveSegment.CurrentKeyStrokes.Add(keyStroke);
        }
예제 #7
0
 public void Evaluate()
 {
     if (KeyStroke.Check(CheckMode))
     {
         Action();
     }
 }
예제 #8
0
        private static CommandKeyBinding CreateCommandKeyBinding(KeyInput input, KeyModifiers modifiers = KeyModifiers.None, string name = "again", string scope = "Global")
        {
            var stroke = new KeyStroke(input, modifiers);
            var key    = new VsVim.KeyBinding(scope, stroke);

            return(new CommandKeyBinding(name, key));
        }
        public void ToStringEncodesPlus()
        {
            var stroke = new KeyStroke(Key.Add);

            Assert.AreEqual("Add", stroke.ToString());
            stroke.Modifiers = ModifierKeys.Alt;
            Assert.AreEqual("Alt+Add", stroke.ToString());
        }
예제 #10
0
        private static void AddKeyStrokeData(KeyStroke keyStroke, List <ComparisonUnit> comparisonUnits, TrackedDocuments trackedDocument)
        {
            var textDelete = string.Empty;

            keyStroke.Text = string.Empty;

            foreach (var comparisonUnit in comparisonUnits)
            {
                switch (comparisonUnit.Type)
                {
                case ComparisonUnit.ComparisonType.New:
                    foreach (var trgu in comparisonUnit.Section)
                    {
                        keyStroke.Text += trgu.Content;
                    }
                    break;

                case ComparisonUnit.ComparisonType.Removed:
                {
                    textDelete = comparisonUnit.Section.Aggregate(textDelete, (current, trgu) => current + trgu.Content);
                }
                break;
                }
            }

            // logical deduction
            // needs to be revised!
            // 1. exclude translations from providers
            // 2. exclude suggestions from termbase? no api handler here... TODO
            // 3. if content changed is greater than 1 char in length then check the key char
            //  - 3.a. if the char == tab or return, then we can assume that this was derived from auto-suggest; however
            //         this does not take into account when the user has selected the auto-suggestion via mouse selection
            if (string.Compare(keyStroke.Key, @"[Tab]", StringComparison.OrdinalIgnoreCase) == 0 && keyStroke.Text.Length > 1)
            {
                keyStroke.OriginType = @"auto-suggest";
            }

            //if the user hit the back key then attempt to get the selection from the comparison if it is not already present
            if (string.Compare(keyStroke.Key, @"[Back]", StringComparison.OrdinalIgnoreCase) == 0 ||
                string.Compare(keyStroke.Key, @"[Delete]", StringComparison.OrdinalIgnoreCase) == 0 &&
                keyStroke.Text == string.Empty &&
                keyStroke.Selection == string.Empty &&
                textDelete != string.Empty)
            {
                keyStroke.Selection = textDelete;
            }


            if (keyStroke.Text == string.Empty && keyStroke.Selection == string.Empty)
            {
                return;
            }

            //add the key stroke object to the list
            trackedDocument.ActiveSegment.CurrentTranslationKeyStokeObjectId     = keyStroke.Id;
            trackedDocument.ActiveSegment.CurrentTranslationKeyStrokeObjectCheck = true;
            trackedDocument.ActiveSegment.CurrentKeyStrokes.Add(keyStroke);
        }
예제 #11
0
 public void KeyStroke3()
 {
     var stroke = new KeyStroke(
         KeyInputUtil.CharToKeyInput('c'),
         KeyModifiers.Shift | KeyModifiers.Control);
     Assert.AreEqual(KeyInputUtil.CharToKeyInput('c'), stroke.KeyInput);
     Assert.AreEqual(KeyInputUtil.CharWithControlToKeyInput('C'), stroke.AggregateKeyInput);
     Assert.AreEqual('c', stroke.Char);
 }
예제 #12
0
 public void Constructor_WithShiftModifier()
 {
     var stroke = new KeyStroke(
         KeyInputUtil.CharToKeyInput('#'),
         KeyModifiers.Shift);
     Assert.Equal(KeyInputUtil.CharToKeyInput('#'), stroke.KeyInput);
     Assert.Equal(KeyInputUtil.ApplyModifiersToVimKey(VimKey.Pound, KeyModifiers.Shift), stroke.AggregateKeyInput);
     Assert.Equal('#', stroke.Char);
 }
예제 #13
0
파일: InputDevice.cs 프로젝트: rflab/Automa
        static public void CenterClick(int x, int y, int delay_ms = 1000)
        {
            //Thread.Sleep(delay_ms);
            var stroke = new KeyStroke();

            stroke.MouseModeTo(x, y, 0);
            stroke.MiddleClick(delay_ms);
            stroke.Send();
        }
예제 #14
0
파일: InputDevice.cs 프로젝트: rflab/Automa
        static public void LeftDoubleClick(int x, int y, int delay_ms = 1000)
        {
            Thread.Sleep(delay_ms);
            var stroke = new KeyStroke();

            stroke.MouseModeTo(x, y, 0);
            stroke.LeftDoubleClick(0);
            stroke.Send();
        }
예제 #15
0
 public void Constructor_WithNoModifier()
 {
     var stroke = new KeyStroke(
         KeyInputUtil.CharToKeyInput('c'),
         KeyModifiers.None);
     Assert.AreEqual(KeyInputUtil.CharToKeyInput('c'), stroke.KeyInput);
     Assert.AreEqual(KeyInputUtil.CharToKeyInput('c'), stroke.AggregateKeyInput);
     Assert.AreEqual('c', stroke.Char);
 }
예제 #16
0
        private void init()
        {
            // dispose the display when the button is clicked
            addActionListener(new ActionListenerAnonymousInnerClass(this));

            // click the button when the ESC key is pressed
            registerKeyboardAction(new ActionListenerAnonymousInnerClass2(this)
                                   , escapeCommand, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
        }
예제 #17
0
파일: InputDevice.cs 프로젝트: rflab/Automa
        static public void MouseMoveTo(int x, int y, int delay_ms = 1000)
        {
            //Thread.Sleep(delay_ms);
            var stroke = new KeyStroke();

            stroke.MouseModeTo(x, y, 0);
            stroke.RightClick(delay_ms);
            stroke.Send();
        }
예제 #18
0
 private static void ProcessKeyStroke(object sender, EventArgs e)
 {
     if (m_PendingKeyStrokes.Count > 0)
     {
         KeyStroke s = m_PendingKeyStrokes[0];
         m_PendingKeyStrokes.RemoveAt(0);
         PressKey(s.key, s.press);
     }
 }
예제 #19
0
 public void KeyStroke_WithShiftAndControlModifier()
 {
     var stroke = new KeyStroke(
         KeyInputUtil.CharToKeyInput('#'),
         KeyModifiers.Shift | KeyModifiers.Control);
     Assert.AreEqual(KeyInputUtil.CharToKeyInput('#'), stroke.KeyInput);
     Assert.AreEqual(KeyInputUtil.VimKeyAndModifiersToKeyInput(VimKey.Pound, KeyModifiers.Shift | KeyModifiers.Control), stroke.AggregateKeyInput);
     Assert.AreEqual('#', stroke.Char);
 }
예제 #20
0
 public void WithShiftModifier()
 {
     var stroke = new KeyStroke(
         KeyInputUtil.CharToKeyInput('#'),
         KeyModifiers.Shift);
     Assert.Equal(KeyInputUtil.CharToKeyInput('#'), stroke.KeyInput);
     Assert.Equal(KeyInputUtil.ApplyModifiersToChar('#', KeyModifiers.Shift), stroke.AggregateKeyInput);
     Assert.Equal('#', stroke.Char);
 }
예제 #21
0
        public void Constructor_WithShiftModifier()
        {
            var stroke = new KeyStroke(
                KeyInputUtil.CharToKeyInput('#'),
                KeyModifiers.Shift);

            Assert.Equal(KeyInputUtil.CharToKeyInput('#'), stroke.KeyInput);
            Assert.Equal(KeyInputUtil.ApplyModifiersToVimKey(VimKey.Pound, KeyModifiers.Shift), stroke.AggregateKeyInput);
            Assert.Equal('#', stroke.Char);
        }
예제 #22
0
파일: KeyStrokeTest.cs 프로젝트: Yzzl/VsVim
 public void WithShiftAndControlModifier()
 {
     var stroke = new KeyStroke(
         KeyInputUtil.CharToKeyInput('#'),
         VimKeyModifiers.Shift | VimKeyModifiers.Control);
     Assert.Equal(KeyInputUtil.CharToKeyInput('#'), stroke.KeyInput);
     Assert.Equal(KeyInputUtil.ApplyKeyModifiersToChar('#', VimKeyModifiers.Shift | VimKeyModifiers.Control),
                  stroke.AggregateKeyInput);
     Assert.Equal('#', stroke.Char);
 }
예제 #23
0
        public void Constructor_WithNoModifier()
        {
            var stroke = new KeyStroke(
                KeyInputUtil.CharToKeyInput('c'),
                KeyModifiers.None);

            Assert.AreEqual(KeyInputUtil.CharToKeyInput('c'), stroke.KeyInput);
            Assert.AreEqual(KeyInputUtil.CharToKeyInput('c'), stroke.AggregateKeyInput);
            Assert.AreEqual('c', stroke.Char);
        }
예제 #24
0
            public void WithShiftModifier()
            {
                var stroke = new KeyStroke(
                    KeyInputUtil.CharToKeyInput('#'),
                    KeyModifiers.Shift);

                Assert.Equal(KeyInputUtil.CharToKeyInput('#'), stroke.KeyInput);
                Assert.Equal(KeyInputUtil.ApplyModifiersToChar('#', KeyModifiers.Shift), stroke.AggregateKeyInput);
                Assert.Equal('#', stroke.Char);
            }
예제 #25
0
        public void KeyStroke_WithShiftAndControlModifier()
        {
            var stroke = new KeyStroke(
                KeyInputUtil.CharToKeyInput('#'),
                KeyModifiers.Shift | KeyModifiers.Control);

            Assert.AreEqual(KeyInputUtil.CharToKeyInput('#'), stroke.KeyInput);
            Assert.AreEqual(KeyInputUtil.VimKeyAndModifiersToKeyInput(VimKey.Pound, KeyModifiers.Shift | KeyModifiers.Control), stroke.AggregateKeyInput);
            Assert.AreEqual('#', stroke.Char);
        }
예제 #26
0
            public void WithShiftAndControlModifier()
            {
                var stroke = new KeyStroke(
                    KeyInputUtil.CharToKeyInput('#'),
                    VimKeyModifiers.Shift | VimKeyModifiers.Control);

                Assert.Equal(KeyInputUtil.CharToKeyInput('#'), stroke.KeyInput);
                Assert.Equal(KeyInputUtil.ApplyKeyModifiersToChar('#', VimKeyModifiers.Shift | VimKeyModifiers.Control),
                             stroke.AggregateKeyInput);
                Assert.Equal('#', stroke.Char);
            }
예제 #27
0
        void OnKeyPressed(object sender, KeyEventArgs args)
        {
            args.Consume();

            var newKey = args.Key != Keys.Escape ? args.Key : Keys.None;

            if (newKey != Keys.None && (ChangeHandler == null || ChangeHandler(newKey)))
            {
                Key = new KeyStroke(newKey, args.Flags);
            }
        }
예제 #28
0
파일: InputDevice.cs 프로젝트: rflab/Automa
        static public void LeftDrag(int x1, int y1, int x2, int y2, int delay_ms = 1000)
        {
            Thread.Sleep(delay_ms);
            var stroke = new KeyStroke();

            stroke.MouseModeTo(x1, y1, 0);
            stroke.LeftDown(200);
            stroke.MouseModeTo(x2, y2, 400);
            stroke.LeftUp(600);
            stroke.Send();
        }
예제 #29
0
파일: KeyStrokeTest.cs 프로젝트: Yzzl/VsVim
 public void Equals1()
 {
     var stroke1 = new KeyStroke(
         KeyInputUtil.CharToKeyInput('c'),
         VimKeyModifiers.Shift | VimKeyModifiers.Control);
     var stroke2 = new KeyStroke(
         KeyInputUtil.CharToKeyInput('c'),
         VimKeyModifiers.Shift | VimKeyModifiers.Control);
     Assert.Equal(stroke1, stroke2);
     Assert.True(stroke1 == stroke2);
     Assert.False(stroke1 != stroke2);
 }
예제 #30
0
 public void Equals2()
 {
     var stroke1 = new KeyStroke(
         KeyInputUtil.CharToKeyInput('d'),
         KeyModifiers.Shift | KeyModifiers.Control);
     var stroke2 = new KeyStroke(
         KeyInputUtil.CharToKeyInput('c'),
         KeyModifiers.Shift | KeyModifiers.Control);
     Assert.AreNotEqual(stroke1, stroke2);
     Assert.IsFalse(stroke1 == stroke2);
     Assert.IsTrue(stroke1 != stroke2);
 }
예제 #31
0
            public void Equals1()
            {
                var stroke1 = new KeyStroke(
                    KeyInputUtil.CharToKeyInput('c'),
                    VimKeyModifiers.Shift | VimKeyModifiers.Control);
                var stroke2 = new KeyStroke(
                    KeyInputUtil.CharToKeyInput('c'),
                    VimKeyModifiers.Shift | VimKeyModifiers.Control);

                Assert.Equal(stroke1, stroke2);
                Assert.True(stroke1 == stroke2);
                Assert.False(stroke1 != stroke2);
            }
예제 #32
0
        public void Equals2()
        {
            var stroke1 = new KeyStroke(
                KeyInputUtil.CharToKeyInput('d'),
                KeyModifiers.Shift | KeyModifiers.Control);
            var stroke2 = new KeyStroke(
                KeyInputUtil.CharToKeyInput('c'),
                KeyModifiers.Shift | KeyModifiers.Control);

            Assert.AreNotEqual(stroke1, stroke2);
            Assert.IsFalse(stroke1 == stroke2);
            Assert.IsTrue(stroke1 != stroke2);
        }
예제 #33
0
        public KeyBox(IUIStyle style, KeyStroke key) : base(style)
        {
            Content = new TextField(style)
            {
                Enabled = false, ReadOnly = true
            };
            Key = key;

            // does not participate in normal focus traversal
            Focusable = false;

            KeyPressed += OnKeyPressed;
            MouseDown  += OnMouseDown;
        }
예제 #34
0
 bool ProcessKeyDownOnFloatingObjectSelected(KeyStroke ks)
 {
     if ((((ks.KeyCode != VirtualKey.Z) || (ks.Modifiers != VirtualKeyModifiers.Control)) && ((ks.KeyCode != VirtualKey.Y) || (ks.Modifiers != VirtualKeyModifiers.Control))) && (HasSelectedFloatingObject() || FloatingObjectKeyMap.ContainsKey(ks)))
     {
         SpreadAction action = null;
         if (FloatingObjectKeyMap.TryGetValue(ks, out action) && (action != null))
         {
             ActionEventArgs e = new ActionEventArgs();
             action(this, e);
             return(e.Handled);
         }
     }
     return(false);
 }
예제 #35
0
    /**
     * The Excel Adapter is constructed with a
     * JTable on which it enables Copy-Paste and acts
     * as a Clipboard listener.
     */
    public ExcelAdapter(atcControls.atcGridSource myJTable, string calculatorType)
    {
        jTable1 = myJTable;
        KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK, false);
        // Identifying the copy KeyStroke user can modify this
        // to copy on some other Key combination.
        KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK, false);

        // Identifying the Paste KeyStroke user can modify this
        //to copy on some other Key combination.
        jTable1.registerKeyboardAction(this, "Copy", copy, JComponent.WHEN_FOCUSED);
        jTable1.registerKeyboardAction(this, "Paste", paste, JComponent.WHEN_FOCUSED);
        // system = Toolkit.getDefaultToolkit().getSystemClipboard();
        this.calculatorType = calculatorType;
    }
예제 #36
0
        private void SendKey(Keys key, KeyState state)
        {
            try
            {
                Stroke    stroke    = new Stroke();
                KeyStroke keyStroke = new KeyStroke();

                keyStroke.Code  = key;
                keyStroke.State = state;

                stroke.Key = keyStroke;

                InterceptionDriver.Send(context, devk, ref stroke, 1);
            }
            catch { Stop(); }
        }
예제 #37
0
    public bool GetKey(KeyCode keycode)
    {
        if (isPlayback)
        {
            for (int i = 0; i < mKeyStrokes.Count; i++)
            {
                float tTime;
                float.TryParse(mKeyStrokes[i].time, out tTime);

                if (mKeyStrokes[i].keyname == keycode.ToString())
                {
                    if (gameTime > tTime - 0.5f && gameTime < tTime + 0.5f)
                    {
                        if (mKeyStrokes[i].state == KeyStroke.State.Pressed)
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
            }
            return(false);
        }
        else if (isRecording)
        {
            KeyStroke keystroke = new KeyStroke();
            keystroke.keyname = keycode.ToString();
            keystroke.time    = gameTime.ToString();
            if (Input.GetKeyDown(keycode))
            {
                keystroke.state = KeyStroke.State.Pressed;
                mKeyStrokes.Add(keystroke);
            }
            else if (Input.GetKeyUp(keycode))
            {
                keystroke.state = KeyStroke.State.Released;
                mKeyStrokes.Add(keystroke);
            }
        }
        return(Input.GetKey(keycode));
    }
        /// <summary>
        /// Is this an advanced key stroke like CTRL+V which we don't want to automatically 
        /// convert.  
        /// </summary>
        private bool IsAdvanced(KeyStroke keyStroke)
        {
            // Look for paste
            if (keyStroke.KeyModifiers != KeyModifiers.Control || keyStroke.KeyInput.KeyModifiers != KeyModifiers.None)
            {
                return false;
            }

            // Look for paste, cut, copy and select all
            switch (keyStroke.KeyInput.Char)
            {
                case 'v':
                case 'x':
                case 'c':
                case 'a':
                    return true;
                default:
                    return false;
            }
        }
        /// <summary>
        /// Is this an advanced key stroke like CTRL+V which we don't want to automatically 
        /// convert.  
        /// </summary>
        private bool IsAdvanced(KeyStroke keyStroke)
        {
            // Look for paste
            if (keyStroke.KeyModifiers == KeyModifiers.Control &&
                keyStroke.KeyInput.Key == VimKey.LowerV &&
                keyStroke.KeyInput.KeyModifiers == KeyModifiers.None)
            {
                return true;
            }

            // Look for cut
            if (keyStroke.KeyModifiers == KeyModifiers.Control &&
                keyStroke.KeyInput.Key == VimKey.LowerX &&
                keyStroke.KeyInput.KeyModifiers == KeyModifiers.None)
            {
                return true;
            }

            return false;
        }
예제 #40
0
        /// <summary>
        /// Is this an advanced key stroke like CTRL+V which we don't want to automatically
        /// convert.
        /// </summary>
        private bool IsAdvanced(KeyStroke keyStroke)
        {
            // Look for paste
            if (keyStroke.KeyModifiers != KeyModifiers.Control || keyStroke.KeyInput.KeyModifiers != KeyModifiers.None)
            {
                return(false);
            }

            // Look for paste, cut, copy and select all
            switch (keyStroke.KeyInput.Char)
            {
            case 'v':
            case 'x':
            case 'c':
            case 'a':
                return(true);

            default:
                return(false);
            }
        }
예제 #41
0
 private static CommandKeyBinding CreateCommandKeyBinding(KeyInput input, KeyModifiers modifiers = KeyModifiers.None, string name = "again", string scope = "Global")
 {
     var stroke = new KeyStroke(input, modifiers);
     var key = new VsVim.KeyBinding(scope, stroke);
     return new CommandKeyBinding(name, key);
 }
예제 #42
0
파일: BMenu.cs 프로젝트: kixtarte/cadencii
 public void setAccelerator( KeyStroke stroke ) {
     base.ShortcutKeys = stroke.keys;
 }
        private static byte ProcessKeyStroke(StringBuilder output, int startIndexOffset, byte shiftDown, SelectionBounds selection, KeyStroke k)
        {
            int relativeIndex = k.cursorPosition - startIndexOffset;
            if (relativeIndex < 0)
                relativeIndex = 0;
            if (k.isKeyPress)
            {
                switch (k.keyCode)
                {
                    case VK_BACK: // Backspace
                        if (relativeIndex == 0)
                        {
                            break;
                        }
                        if(output.Length > 0)
                        {
                            if (!selection.isEmpty())
                            {
                                if (selection.start < 0)
                                    selection.start = 0;
                                else if (selection.start >= output.Length)
                                    selection.start = output.Length - 1;

                                if (selection.end < 0)
                                    selection.end = 0;
                                else if (selection.end >= output.Length)
                                    selection.end = output.Length - 1;

                                selection.checkOrder();

                                output.Remove(selection.start, selection.end - selection.start);
                                selection.start = selection.end = -1;
                            }
                            else
                            {
                                if (relativeIndex > output.Length - 1)
                                    relativeIndex = output.Length - 1;
                                output.Remove(relativeIndex, 1);
                            }
                        }
                        break;

                    case VK_SHIFT:
                        shiftDown |= 0x04;
                        if (selection.isActive())
                        { // There is already an active
                            // selection -- hitting select again
                            // shouldn't change anything
                            break;
                        }
                        // selection
                        selection.start = relativeIndex;
                        selection.end = relativeIndex;
                        break;
                    case VK_LSHIFT:
                        shiftDown |= 0x02;
                        if (selection.isActive())
                        { // There is already an active
                            // selection -- hitting select again
                            // shouldn't change anything
                            break;
                        }
                        // selection
                        selection.start = relativeIndex;
                        selection.end = relativeIndex;
                        break;
                    case VK_RSHIFT: // Shift
                        shiftDown |= 0x01;
                        if (selection.isActive())
                        { // There is already an active
                            // selection -- hitting select again
                            // shouldn't change anything
                            break;
                        }
                        // selection
                        selection.start = relativeIndex;
                        selection.end = relativeIndex;
                        break;
                    case VK_DELETE: // Delete
                        if (relativeIndex > output.Length - 1)
                        {
                            break;
                        }
                        if (!selection.isEmpty())
                        {
                            selection.checkOrder();
                            output.Remove(selection.start, selection.end - selection.start);
                        }
                        else
                        {
                            output.Remove(relativeIndex, 1);
                        }
                        selection.start = selection.end = -1;

                        break;
                    case VK_LEFT: // 37: // Arrows
                        if (shiftDown == 0)
                        {
                            // clear the selection, if not currently shifting.
                            selection.start = selection.end = -1;
                        }
                        else if (selection.isActive())
                        {
                            selection.end = relativeIndex - 1;
                        }
                        break;
                    case VK_RIGHT: // 39:
                        if (shiftDown == 0)
                        {
                            // clear the selection, if not currently shifting.
                            selection.start = selection.end = -1;
                        }
                        else if (selection.isActive())
                        {
                            selection.end = relativeIndex + 1;
                        }
                        break;
                    case 38:
                    case 40:
                        if (shiftDown == 0)
                        {
                            // clear the selection, if not currently shifting.
                            selection.start = selection.end = -1;
                        }
                        else if (selection.isActive())
                        {
                            selection.end = relativeIndex;
                        }
                        break;
                    default:
                        if (k.keyChar == 65535)
                        {
                            break;
                        }
                        if (k.keyChar < 9) // nonprinted
                        {
                            break;
                        }
                        if (k.keyChar > 11 && k.keyChar < 13)
                        {
                            break;
                        }
                        if (k.keyChar > 13 && k.keyChar < 32)
                        {
                            break;
                        }
                        // Printable characters
                        if (selection.isActive() && !selection.isEmpty())
                        {
                            selection.checkOrder();
                            if (selection.start < output.Length)
                            {
                                if (selection.end < output.Length)
                                    output.Remove(selection.start, selection.end - selection.start);
                                else
                                    output.Remove(selection.start, output.Length - selection.start);
                            }
                        }
                        if (relativeIndex < 0)
                        {
                            relativeIndex = 0;
                        }
                        if (relativeIndex > output.Length)
                        {
                            relativeIndex = output.Length;
                        }
                        output.Insert(relativeIndex, k.keyChar);
                        // After a printed character the selection is cleared.
                        selection.start = selection.end = -1;
                        break;
                }
            }
            else
            {
                if (k.keyCode == VK_LSHIFT)
                {
                    shiftDown &= 0xFD;
                }
                else if (k.keyCode == VK_SHIFT)
                {
                    shiftDown &= 0xFB;
                }
                else if (k.keyCode == VK_RSHIFT)
                {
                    shiftDown &= 0xFE;
                }
            }
            return shiftDown;
        }
예제 #44
0
        /// <summary>
        /// There are a set of TSQL command entries which a) have no name and b) use keystrokes 
        /// Vim users would like to use.  In general this isn't a problem becuase VsVim is 
        /// capable of removing conflicting key bindings via the options page
        /// 
        /// The problem here is the commands are unnamed.  Any attempt to change a key binding
        /// on an unnamed command (via Command::put_Bindings) will fail.  There is no good reason
        /// for this that I was able to track down, it's just the behavior.  
        /// 
        /// There is some hope this can be changed in 2015 or the next release but in the 
        /// short term I need to use a different hammer for changing the key bindings.  This method
        /// method removes the binding by doing the following
        /// 
        ///   1. Add a key binding to a VsVim command where the key binding has the same scope as the 
        ///      TSQL key bindings 
        ///   2. Remove the key bindings on the VsVim command
        ///
        /// As a consequence of adding the key binding in #1 Visual Studio will delete the key 
        /// binding on the TSQL command.  This type of deletion doesn't check for a name and hence 
        /// succeeds.  The subsequent removal of the key binding to the fake VsVim command effectively 
        /// fully clears the key binding which is what we want
        /// </summary>
        private void ClearTSQLBindings()
        {
            try
            {
                var vsServiceProvider = _exportProvider.GetExportedValue<SVsServiceProvider>();
                var dte = vsServiceProvider.GetService<SDTE, _DTE>();

                var vsvimGuidGroup = GuidList.VsVimCommandSet;
                var vimCommand = dte.Commands.GetCommands()
                    .Where(c => new Guid(c.Guid) == vsvimGuidGroup && c.ID == CommandIds.ClearTSQLBindings)
                    .FirstOrDefault();
                if (vimCommand == null)
                {
                    return;
                }

                var targetKeyStroke = new KeyStroke(KeyInputUtil.CharToKeyInput('d'), VimKeyModifiers.Control);
                var tsqlGuidGroup = new Guid("{b371c497-6d81-4b13-9db8-8e3e6abad0c3}");
                var tsqlCommands = dte.Commands.GetCommands().Where(c => new Guid(c.Guid) == tsqlGuidGroup);
                foreach (var tsqlCommand in tsqlCommands)
                {
                    foreach (var commandKeyBinding in tsqlCommand.GetCommandKeyBindings().ToList())
                    {
                        if (commandKeyBinding.KeyBinding.FirstKeyStroke == targetKeyStroke)
                        {
                            // Set the binding to the existing command in the existing scope, this will delete it from
                            // the TSQL command
                            vimCommand.SafeSetBindings(commandKeyBinding.KeyBinding);

                            // Clear the bindings here which will effectively clear the binding completely
                            vimCommand.SafeResetBindings();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.Message);
            }
        }
예제 #45
0
 private static void QueueKey(KeyStroke ks)
 {
     InitKeystrokeTimer();
     m_PendingKeyStrokes.Add(ks);
 }
예제 #46
0
 /// <summary>
 /// Creates a mapping of a key stroke character, it's associated KeyStroke.
 /// Internationalization will require these mappings to be different between languagues. A provider is 
 /// required to map to the keyboard mapping per language.
 /// </summary>
 /// <param name="pCharacter">The character being mapped.</param>
 /// <param name="pKeyStroke">The associated KeyStroke</param>
 public KeyStrokeMapping(char pCharacter, KeyStroke pKeyStroke)
 {
     _character = pCharacter;
     _keyStroke = pKeyStroke;
 }
예제 #47
0
 public void setAccelerator( KeyStroke stroke ) {
 }
예제 #48
0
 internal static KeyCharModifier Create(KeyStroke stroke)
 {
     return new KeyCharModifier(stroke.Char, stroke.KeyModifiers);
 }