Multiple Key Gestures

SyntaxEditor for WPF Forum

Posted 10 years ago by Mick George - Software Engineer, CNC Software, Inc.
Version: 11.1.0545
Avatar
Hi,

I am trying to replicate Visual Studios shortcut key gestures for outlining, one example would be the following key gestures to toggle code outlining; CTRL+M followed by CTRL+L.

I have been unable, thus far, to find anything "out of the box" that would accomplish this functionality, is this functionality available and I missed it?

Thanks.

Comments (3)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Mick,

Sorry, WPF doesn't include support "chord" key gestures and we don't have any WPF products at this time to do them.


Actipro Software Support

Posted 10 years ago by Mick George - Software Engineer, CNC Software, Inc.
Avatar
Thank you for the clarification.
Posted 5 years ago by Matt Whitfield
Avatar

Ok, so I'm digging up old threads again, but, based on http://stackoverflow.com/questions/2181991/multi-key-gesture-in-wpf you can do this:

class KeyChordGesture : KeyGesture
    {
        private readonly Key _key;
        private bool _gotFirstGesture;
        private readonly InputGesture _firstGesture;

        public KeyChordGesture(ModifierKeys modifier, Key firstKey, Key secondKey) : base(Key.None)
        {
            _firstGesture = new KeyGesture(firstKey, modifier);
            _key = secondKey;
        }

        public override bool Matches(object obj, InputEventArgs inputEventArgs)
        {
            var keyArgs = inputEventArgs as KeyEventArgs;
            if (keyArgs == null || keyArgs.IsRepeat)
            {
                return false;
            }

            if (_gotFirstGesture)
            {
                _gotFirstGesture = false;

                if (keyArgs.Key == _key)
                {
                    inputEventArgs.Handled = true;
                }

                return keyArgs.Key == _key;
            }
            
            _gotFirstGesture = _firstGesture.Matches(null, inputEventArgs);
            if (_gotFirstGesture)
            {
                inputEventArgs.Handled = true;
            }

            return false;
        }
    }

 Then associate it like this:

Editor.InputBindings.Add(new KeyBinding(EditorCommands.SelectAll, 
    new KeyChordGesture(ModifierKeys.Control, Key.K, Key.X)));

 Hope that helps anyone looking in the future.

The latest build of this product (v21.1.1) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.