private void OnHotKeyPressed(object sender, KeyPressedEventArgs e)
        {
            var kc = new KeyConverter();

            if (e.HotKey.Key == (Key)kc.ConvertFromString(Settings.Default.hotKeyQ))
            {
                ForegroundW.SetForeground("Shell_TrayWnd");
                textBox.Focus();
                textBox.Clear();
            }
            if (e.HotKey.Key == (Key)kc.ConvertFromString(Settings.Default.hotKeyW))
            {
                if (Shower == null)
                {
                    Shower = new QShower();
                }

                Shower.ShowOrHide(ActualHeight, ActualWidth, PointToScreen(new Point()).X);
            }
            if (e.HotKey.Key == (Key)kc.ConvertFromString(Settings.Default.hotKeyB))
            {
                Sim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_C);
                Thread.Sleep(20);
                string str = ClipboardGetText();
                Process.Start("https://www.baidu.com/s?ie=UTF-8&wd=" + str);
            }
            if (e.HotKey.Key == (Key)kc.ConvertFromString(Settings.Default.hotKeyG))
            {
                Sim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_C);
                Thread.Sleep(20);
                string str = ClipboardGetText();
                Process.Start("http://google.com#q=" + str);
            }
        }
示例#2
0
 int score2;                             // score aangepast zodat het iets leuker is dan aantal opgegeten//score aanpassen zodat bijkomende score2 = score2+ score*300/intervaltijd
 #endregion
 public Window1()
 {
     keys[0] = Key.Up; //maken dat keys worden opgeslagen bij properties.settings
     keys[1] = Key.Down;
     keys[2] = Key.Left;
     keys[3] = Key.Right;//in catch blok plaatsen als he werkt om zo default keys te hebben
     try
     {
         keys[0] = (Key)kc.ConvertFromString(Properties.Settings.Default.up);
         keys[1] = (Key)kc.ConvertFromString(Properties.Settings.Default.down);
         keys[2] = (Key)kc.ConvertFromString(Properties.Settings.Default.left);
         keys[3] = (Key)kc.ConvertFromString(Properties.Settings.Default.right);
     }
     catch
     {
     }
     //werkt niet
     //Enum.TryParse(Properties.Settings.Default.up, out keys[0]);
     //Enum.TryParse(Properties.Settings.Default.down, out keys[1]);
     //Enum.TryParse(Properties.Settings.Default.left, out keys[2]);
     //Enum.TryParse(Properties.Settings.Default.right, out keys[3]);
     //bestudeer class System.Windows.Input.Keyconverter
     //keys[0] = Properties.Settings.Default.up;
     spelGroote = 20;
     InitializeComponent();
     InitialiseerVeld();
     aantalGames          = 0;
     highscore            = 0;
     difficulty           = 2;
     rb2.IsChecked        = true;
     gemiddeld.IsChecked  = true;
     this.highscore       = Properties.Settings.Default.highscore; // ◄--oorspronkelijke versie(haalt geen score uit database)
     lblHighScore.Content = highscore;
 }
        private void CargarTeclas()
        {
            Variable var = Compartidos.ObtenerVariablesConfiguracion();

            var.LeerArchivo();
            teclas.Clear();
            for (int i = 1; i <= 9; i++)
            {
                try
                {
                    String       valor = var.ObtenerValorVariable <String>("TECLA_" + i);
                    KeyConverter k     = new KeyConverter();
                    Key          mykey = Key.Zoom;
                    if (valor != null && valor.Trim().Equals(""))
                    {
                        mykey = (Key)k.ConvertFromString("NumPad" + i);
                    }
                    else
                    {
                        mykey = (Key)k.ConvertFromString(valor);
                    }
                    teclas.Add(mykey.ToString());
                }
                catch { }
            }
        }
示例#4
0
        private void Load(string path, string basePath)
        {
            if (!File.Exists(basePath))
            {
                return;
            }

            var xmlBaseReader = new CommonXmlReader(basePath);
            var baseDic       = new KeyConfigDictionary()
            {
                { "shortcutnames", xmlBaseReader.GetAttributes("shortcutname", "shortcuts/shortcut") },
                { "specialkeies", xmlBaseReader.GetAttributes("specialkey", "shortcuts/shortcut") },
                { "mainkeies", xmlBaseReader.GetAttributes("mainkey", "shortcuts/shortcut") },
                { "descriptions", xmlBaseReader.GetValues("shortcuts/shortcut") }
            };

            var modConverter = new ModifierKeysConverter();
            var keyConverter = new KeyConverter();

            for (int i = 0; i < baseDic.MinValueCount; ++i)
            {
                ModifierKeys specialKey = (ModifierKeys)modConverter.ConvertFromString(baseDic["specialkeies"][i]);
                Key          mainKey    = (Key)keyConverter.ConvertFromString(baseDic["mainkeies"][i]);
                ShortcutKeies.Add(baseDic["shortcutnames"][i],
                                  new ShortcutKey(baseDic["shortcutnames"][i], specialKey, mainKey, baseDic["descriptions"][i].TrimEnd('\n').TrimEnd('\r')));
            }

            if (!File.Exists(path))
            {
                return;
            }

            var xmlReader = new CommonXmlReader(path);
            var dic       = new KeyConfigDictionary
            {
                { "shortcutnames", xmlReader.GetAttributes("shortcutname", "shortcuts/shortcut") },
                { "specialkeies", xmlReader.GetAttributes("specialkey", "shortcuts/shortcut") },
                { "mainkeies", xmlReader.GetAttributes("mainkey", "shortcuts/shortcut") }
            };

            for (int i = 0; i < dic.MinValueCount; ++i)
            {
                ModifierKeys specialKey;
                if (dic["specialkeies"][i].Equals("None"))
                {
                    specialKey = ModifierKeys.None;
                }
                else
                {
                    specialKey = (ModifierKeys)modConverter.ConvertFromString(dic["specialkeies"][i]);
                }
                Key    mainKey     = (Key)keyConverter.ConvertFromString(dic["mainkeies"][i]);
                string description = ShortcutKeies[dic["shortcutnames"][i]].Description;
                ShortcutKeies[dic["shortcutnames"][i]] = new ShortcutKey(dic["shortcutnames"][i], specialKey, mainKey, description);
            }
            return;
        }
示例#5
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value is string)
            {
                string bindingString = value as string;

                if (!string.IsNullOrEmpty(bindingString))
                {
                    KeyBinding keybind = new KeyBinding();

                    string[] values = bindingString.Split('+');

                    for (int i = 0; i < values.Length; i++)
                    {
                        if (i == values.Length - 1)
                        {
                            KeyConverter k = new KeyConverter();
                            keybind.Key = (Key)k.ConvertFromString(values[i]);
                        }
                        else
                        {
                            ModifierKeysConverter conv = new ModifierKeysConverter();
                            keybind.Modifiers = keybind.Modifiers | (ModifierKeys)conv.ConvertFromString(values[i]);
                        }
                    }

                    return(keybind);
                }

                return(null);
            }

            return(null);
        }
示例#6
0
        private void EditInputBinding(MenuItem menu, ModifierKeys modifier)
        {
            KeyConverter           k   = new KeyConverter();
            Key                    key = (Key)k.ConvertFromString(menu.InputGestureText);
            InputBindingCollection InputBindingsCopy = new InputBindingCollection(InputBindings);

            foreach (KeyBinding item in InputBindingsCopy)
            {
                if (item.Key == key)
                {
                    if (modifier == ModifierKeys.None)
                    {
                        InputBindings.Remove(item);
                    }
                    else
                    {
                        item.Modifiers = modifier;
                        if (modifier == ModifierKeys.Control)
                        {
                            menu.InputGestureText = "CTRL+" + menu.InputGestureText;
                        }
                    }
                    break;
                }
            }
        }
示例#7
0
        private void ParseKeyString(string hotkey)
        {
            string ksc = hotkey.ToLower();

            if (ksc.Contains("alt"))
            {
                GestureModifier = ModifierKeys.Alt;
            }
            if (ksc.Contains("shift"))
            {
                GestureModifier |= ModifierKeys.Shift;
            }
            if (ksc.Contains("ctrl") || ksc.Contains("ctl"))
            {
                GestureModifier |= ModifierKeys.Control;
            }

            string key =
                ksc.Replace("+", "")
                .Replace("-", "")
                .Replace("_", "")
                .Replace(" ", "")
                .Replace("alt", "")
                .Replace("shift", "")
                .Replace("ctrl", "")
                .Replace("ctl", "");

            key = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(key);
            if (!string.IsNullOrEmpty(key))
            {
                KeyConverter k = new KeyConverter();
                GestureKey = (Key)k.ConvertFromString(key);
            }
        }
示例#8
0
        public Hotkey(string keystring)
        {
            string ksc = keystring.ToLower();

            if (ksc.Contains("alt"))
            {
                Modifiers = ModifierKeys.Alt;
            }
            if (ksc.Contains("shift"))
            {
                Modifiers |= ModifierKeys.Shift;
            }
            if (ksc.Contains("ctrl") || ksc.Contains("ctl"))
            {
                Modifiers |= ModifierKeys.Control;
            }

            string key =
                ksc.Replace("+", "")
                .Replace("-", "")
                .Replace("_", "")
                .Replace(" ", "")
                .Replace("alt", "")
                .Replace("shift", "")
                .Replace("ctrl", "")
                .Replace("ctl", "");

            key = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(key);
            if (!string.IsNullOrEmpty(key))
            {
                KeyConverter k = new KeyConverter();
                Key = (Key)k.ConvertFromString(key);
            }
        }
        private List <List <VirtualKeyCode> > processKeyboardShortcutAsString(string shortcut)
        {
            List <List <VirtualKeyCode> > result        = new List <List <VirtualKeyCode> >();
            List <VirtualKeyCode>         listModifiers = new List <VirtualKeyCode>();
            List <VirtualKeyCode>         listKey       = new List <VirtualKeyCode>();

            if (shortcut.Contains("Ctrl"))
            {
                listModifiers.Add(VirtualKeyCode.CONTROL);
                shortcut = shortcut.Replace("Ctrl", "");
            }
            if (shortcut.Contains("Shift"))
            {
                listModifiers.Add(VirtualKeyCode.SHIFT);
                shortcut = shortcut.Replace("Shift", "");
            }
            if (shortcut.Contains("Alt"))
            {
                listModifiers.Add(VirtualKeyCode.MENU);
                shortcut = shortcut.Replace("Alt", "");
            }
            if (shortcut.Contains("Win"))
            {
                listModifiers.Add(VirtualKeyCode.LWIN);
                shortcut = shortcut.Replace("Win", "");
            }
            shortcut = shortcut.Replace("+", "");
            KeyConverter k   = new KeyConverter();
            Key          key = (Key)k.ConvertFromString(shortcut);

            listKey.Add((VirtualKeyCode)KeyInterop.VirtualKeyFromKey(key));
            result.Add(listModifiers);
            result.Add(listKey);
            return(result);
        }
示例#10
0
        public static Key StringAKey(String str)
        {
            KeyConverter k     = new KeyConverter();
            Key          mykey = (Key)k.ConvertFromString(str);

            return(mykey);
        }
 void SeleccionarTecla_KeyDown(object sender, KeyEventArgs e)
 {
     txt_tecla.Text    = e.Key.ToString();
     TeclaSeleccionada = e.Key;
     KeyConverter k     = new KeyConverter();
     Key          mykey = (Key)k.ConvertFromString(txt_tecla.Text);
 }
示例#12
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (Keyboard.IsKeyDown(Key.LeftCtrl) && Keyboard.IsKeyDown(Key.LeftAlt) && Keyboard.IsKeyDown(Key.LeftShift) && Keyboard.IsKeyDown(Key.Z))
            {
                chkToggled.Checked = false;
                cmdToggle.Text     = "Start";
            }
            if (txtTrigger.Text != "")
            {
                KeyConverter c   = new KeyConverter();
                Key          key = txtTrigger.Text.Length == 1 ? (Key)c.ConvertFromString(txtTrigger.Text) : getSpecialKey(txtTrigger.Text);

                if (Keyboard.IsKeyDown(key) || chkToggled.Checked)
                {
                    DoInput();
                }
            }
            else if (chkLeft.Checked)
            {
                if ((MouseButtons & MouseButtons.Left) == MouseButtons.Left || chkToggled.Checked)
                {
                    DoInput();
                }
            }
            else if (chkRight.Checked)
            {
                if ((MouseButtons & MouseButtons.Right) == MouseButtons.Right || chkToggled.Checked)
                {
                    DoInput();
                }
            }

            txtClicks.Text = clicks.ToString();
        }
        private Key StringToKey(string text)
        {
            KeyConverter k     = new KeyConverter();
            Key          mykey = (Key)k.ConvertFromString(text);

            return(mykey);
        }
示例#14
0
        public override void OnWindowLoaded()
        {
            bool requiresCompiler = false;

            foreach (var snippet in SnippetsAddinConfiguration.Current.Snippets)
            {
                if (!requiresCompiler && snippet.SnippetText.Contains("{{") || snippet.SnippetText.Contains("@"))
                {
                    requiresCompiler = true;
                }


                if (!string.IsNullOrEmpty(snippet.KeyboardShortcut))
                {
                    var        ksc = snippet.KeyboardShortcut.ToLower();
                    KeyBinding kb  = new KeyBinding();

                    if (ksc.Contains("alt"))
                    {
                        kb.Modifiers = ModifierKeys.Alt;
                    }
                    if (ksc.Contains("shift"))
                    {
                        kb.Modifiers |= ModifierKeys.Shift;
                    }
                    if (ksc.Contains("ctrl") || ksc.Contains("ctl"))
                    {
                        kb.Modifiers |= ModifierKeys.Control;
                    }

                    string key =
                        ksc.Replace("+", "")
                        .Replace("-", "")
                        .Replace("_", "")
                        .Replace(" ", "")
                        .Replace("alt", "")
                        .Replace("shift", "")
                        .Replace("ctrl", "")
                        .Replace("ctl", "");

                    key = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(key);
                    if (!string.IsNullOrEmpty(key))
                    {
                        KeyConverter k = new KeyConverter();
                        kb.Key = (Key)k.ConvertFromString(key);
                    }

                    // Whatever command you need to bind to
                    kb.Command = new CommandBase((s, e) => InsertSnippet(snippet),
                                                 (s, e) => Model.IsEditorActive);

                    Model.Window.InputBindings.Add(kb);
                }
            }

            if (requiresCompiler)
            {
                RoslynLifetimeManager.WarmupRoslyn();
            }
        }
示例#15
0
        public void RegisterHook(string targetKey, Action <Key> keyAction, bool singleFire = true)
        {
            KeyConverter converter = new KeyConverter();
            Key          _key      = (Key)converter.ConvertFromString(targetKey);

            RegisterHook(_key, keyAction, singleFire);
        }
示例#16
0
        public static void SetupSleepShortcut(WindowInteropHelper helper)
        {
            var shortcut = Properties.Settings.Default.SleepShortcut.ToLower();

            string keyString = shortcut.Substring(shortcut.Length - 1);
            var    modifiers = 0;

            if (shortcut.Contains("alt"))
            {
                modifiers += 1;
            }

            if (shortcut.Contains("ctrl"))
            {
                modifiers += 2;
            }

            if (shortcut.Contains("shift"))
            {
                modifiers += 4;
            }

            var keyConverter = new KeyConverter();
            var key          = (Key)keyConverter.ConvertFromString(keyString);

            RegisterHotKey(helper.Handle, HotkeyId, modifiers, KeyInterop.VirtualKeyFromKey(key));
        }
示例#17
0
        private void setKeyFromString(string strKeys)
        {
            KeyConverter k = Target.keyConverter;

            this.Key = (Key)k.ConvertFromString(strKeys.Substring(strKeys.LastIndexOf("+") + 1));
            // TODO: Error process
        }
示例#18
0
        /// <summary>
        /// Creates a keyboard shortcut from a
        /// </summary>
        /// <param name="ksc"></param>
        /// <param name="command"></param>
        /// <returns>KeyBinding - Window.InputBindings.Add(keyBinding)</returns>
        public static KeyBinding CreateKeyboardShortcutBinding(string ksc, ICommand command)
        {
            if (string.IsNullOrEmpty(ksc))
            {
                return(null);
            }

            try
            {
                KeyBinding kb = new KeyBinding();
                ksc = ksc.ToLower();

                if (ksc.Contains("alt"))
                {
                    kb.Modifiers = ModifierKeys.Alt;
                }
                if (ksc.Contains("shift"))
                {
                    kb.Modifiers |= ModifierKeys.Shift;
                }
                if (ksc.Contains("ctrl") || ksc.Contains("ctl"))
                {
                    kb.Modifiers |= ModifierKeys.Control;
                }
                if (ksc.Contains("win"))
                {
                    kb.Modifiers |= ModifierKeys.Windows;
                }

                string key =
                    ksc.Replace("+", "")
                    .Replace("-", "")
                    .Replace("_", "")
                    .Replace(" ", "")
                    .Replace("alt", "")
                    .Replace("shift", "")
                    .Replace("ctrl", "")
                    .Replace("ctl", "");

                key = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(key);
                if (!string.IsNullOrEmpty(key))
                {
                    KeyConverter k = new KeyConverter();
                    kb.Key = (Key)k.ConvertFromString(key);
                }

                // Whatever command you need to bind to
                kb.Command = command;

                return(kb);
            }
            // deal with invalid bindings - ignore them
            catch (Exception ex)
            {
                mmApp.Log("Unable to assign key binding: " + ksc, ex);
                return(null);
            }
        }
示例#19
0
        public virtual void SetKeys(string modifiers, string key)
        {
            ModifierKeysConverter mod_ser = new ModifierKeysConverter();

            Modifiers_ = (ModifierKeys)mod_ser.ConvertFromString(modifiers);
            KeyConverter key_ser = new KeyConverter();

            Key_ = (Key)key_ser.ConvertFromString(key);
        }
示例#20
0
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is string))
            {
                throw new ArgumentException();
            }
            var conv = new KeyConverter();

            return(conv.ConvertFromString(value.ToString()));
        }
        private static List <Key> StringToKeys(string text)
        {
            var keyConverter = new KeyConverter();

            var split = text.Split(' ');

            return(split.Select(s => keyConverter.ConvertFromString(s))
                   .Where(x => x != null)
                   .Select(x => (Key)x)
                   .ToList());
        }
示例#22
0
        /// <summary>
        /// Creates a new Note object.
        /// </summary>
        /// <param name="noteCharacter">The corresponding Tower Unite note character.</param>
        /// <param name="isShifted">Whether the shift key is required for this note or not.</param>
        public Note(char noteCharacter, bool isShifted = false)
        {
            NoteCharacter = noteCharacter;
            IsShiftedKey  = isShifted;

            //Converting the character into a VirtualKeyCode, something the InputSimulator can read.
            KeyConverter converter = new KeyConverter();
            Key          key       = (Key)converter.ConvertFromString(noteCharacter.ToString());

            KeyCode = (VirtualKeyCode)KeyInterop.VirtualKeyFromKey(key);
        }
        /// <summary>
        /// Sends key strokes to the provided viewmodel.
        /// If the input would cause the intellisense window to
        /// trigger, the intellisense callback is invoked.
        /// </summary>
        /// <param name="keyStrokes">A FormattableString (not a string!) that contains keystrokes</param>
        /// <param name="vm">window view model</param>
        /// <param name="intellisenseCallback"></param>
        /// <returns></returns>
        private async Task TypeInput(FormattableString keyStrokes, WindowViewModel vm, TriggerIntellisense intellisenseCallback = null)
        {
            var          device   = new MockKeyboardDevice(InputManager.Current);
            ModifierKeys modifier = ModifierKeys.None;

            foreach (var stroke in ConvertToKeys(keyStrokes))
            {
                var currentLine = vm.Entries[vm.FocusIndex];

                // set up document state; in the real app this is done by databinding
                if (currentLine.Document is null)
                {
                    var editor = new TextEditor {
                        Document = new TextDocument()
                    };
                    currentLine.Document ??= editor.Document;
                    currentLine.SetEditor(editor);
                    currentLine.TriggerIntellisense ??= intellisenseCallback ?? ((items) => { });
                }

                // convert to input to the appropriate key press
                Key key;
                switch (stroke)
                {
                case char ch:     // type the character into the editor and set up the key event
                    currentLine.Document.Text += ch;
                    currentLine.CaretOffset    = currentLine.Document.Text.Length;
                    key = CharToKey.ContainsKey(ch)
                            ? CharToKey[ch]
                            : (Key)keyConverter.ConvertFromString(ch.ToString());
                    break;

                case Key k:
                    key = k;
                    break;

                case ModifierKeys mod:
                    modifier |= mod;
                    continue;

                default:
                    throw new InvalidOperationException("Unhandled type: " + stroke.GetType());
                }

                device.ModifierKeysImpl = modifier;
                var keyDown = device.CreateKeyEventArgs(key, Keyboard.KeyDownEvent);
                await viewModelService.HandleKeyDown(vm, currentLine, keyDown);

                var keyUp = device.CreateKeyEventArgs(key, Keyboard.KeyUpEvent);
                await viewModelService.HandleKeyUp(vm, currentLine, keyUp);

                modifier = ModifierKeys.None;
            }
        }
示例#24
0
 public InputTest()
 {
     InitializeComponent();
     k1      = (Key)kc.ConvertFromString("Up");
     k2      = Key.Down;
     k3      = Key.Left;
     k4      = Key.Right;
     keys[0] = k1;
     keys[1] = k2;
     keys[2] = k3;
     keys[3] = k4;
 }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string stringKey = value as string;

            if (stringKey == null)
            {
                return(Key.None);
            }
            KeyConverter keyConverter = new KeyConverter();
            Key          result       = (Key)keyConverter.ConvertFromString(stringKey);

            return(result);
        }
示例#26
0
 public void Enable()
 {
     //Console.WriteLine("HotkeyModule is enebled");;
     _listener.HookedKeys.Clear();
     foreach (Hotkey k in hotkeys)
     {
         //add from hooked keys
         //Console.WriteLine("Adding " + k.Key.ToString() + " from hooked keys...");
         Key mykey = (Key)keyConverter.ConvertFromString(k.Key);
         _listener.HookedKeys.Add(mykey);
     }
     _listener.HookKeyboard();
 }
示例#27
0
        /// <summary>
        /// Creates a keyboard shortcut from a
        /// </summary>
        /// <param name="ksc"></param>
        /// <param name="command"></param>
        /// <returns>KeyBinding - Window.InputBindings.Add(keyBinding)</returns>
        public static KeyBinding CreateKeyboardShortcutBinding(string ksc, ICommand command)
        {
            if (string.IsNullOrEmpty(ksc))
            {
                return(null);
            }

            KeyBinding kb = new KeyBinding();

            ksc = ksc.ToLower();

            if (ksc.Contains("alt"))
            {
                kb.Modifiers = ModifierKeys.Alt;
            }
            if (ksc.Contains("shift"))
            {
                kb.Modifiers |= ModifierKeys.Shift;
            }
            if (ksc.Contains("ctrl") || ksc.Contains("ctl"))
            {
                kb.Modifiers |= ModifierKeys.Control;
            }
            if (ksc.Contains("win"))
            {
                kb.Modifiers |= ModifierKeys.Windows;
            }

            string key =
                ksc.Replace("+", "")
                .Replace("-", "")
                .Replace("_", "")
                .Replace(" ", "")
                .Replace("alt", "")
                .Replace("shift", "")
                .Replace("ctrl", "")
                .Replace("ctl", "");

            key = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(key);
            if (!string.IsNullOrEmpty(key))
            {
                KeyConverter k = new KeyConverter();
                kb.Key = (Key)k.ConvertFromString(key);
            }

            // Whatever command you need to bind to
            kb.Command = command;

            return(kb);
        }
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object source)
        {
            if (source is string)
            {
                var    str      = (string)source;
                string fullName = str.Trim();
                if (fullName == "")
                {
                    return(new AnyKeyGesture(Key.None));
                }

                string keyToken;
                string modifiersToken;
                string displayString;

                // Break apart display string
                int index = fullName.IndexOf(DisplayStringSeparator);
                if (index >= 0)
                {
                    displayString = fullName.Substring(index + 1).Trim();
                    fullName      = fullName.Substring(0, index).Trim();
                }
                else
                {
                    displayString = "";
                }

                // Break apart key and modifiers
                index = fullName.LastIndexOf(ModifiersDelimiter);
                if (index >= 0)
                {
                    modifiersToken = fullName.Substring(0, index);
                    keyToken       = fullName.Substring(index + 1);
                }
                else
                {
                    modifiersToken = "";
                    keyToken       = fullName;
                }

                return(new AnyKeyGesture(
                           _keyConverter.ConvertFromString <Key>(keyToken, culture, context),
                           _modifierKeysConverter.ConvertFromString <ModifierKeys>(modifiersToken, culture, context),
                           displayString));
            }
            throw GetConvertFromException(source);
        }
        public MultiKeyGestureExtension(params string[] textPieces)
        {
            var text = ", ".Join(textPieces);

            if (text.Contains("+"))
            {
                var parts = text.Split('+');
                text = parts[1];
                mods = (ModifierKeys)modifierConverter.ConvertFromString(parts[0]);
            }
            else
            {
                mods = ModifierKeys.None;
            }

            keys = text.Split(',').Select(k => (Key)keyConverter.ConvertFromString(k.Trim())).ToArray();
        }
示例#30
0
        private static void AddKeyboardShortcut(AddInMenuItem menuItem, MarkdownMonsterAddin addin)
        {
            if (!string.IsNullOrEmpty(menuItem.KeyboardShortcut))
            {
                var        ksc = menuItem.KeyboardShortcut.ToLower();
                KeyBinding kb  = new KeyBinding();

                if (ksc.Contains("alt"))
                {
                    kb.Modifiers = ModifierKeys.Alt;
                }
                if (ksc.Contains("shift"))
                {
                    kb.Modifiers |= ModifierKeys.Shift;
                }
                if (ksc.Contains("ctrl") || ksc.Contains("ctl"))
                {
                    kb.Modifiers |= ModifierKeys.Control;
                }
                if (ksc.Contains("win"))
                {
                    kb.Modifiers |= ModifierKeys.Windows;
                }

                string key =
                    ksc.Replace("+", "")
                    .Replace("-", "")
                    .Replace("_", "")
                    .Replace(" ", "")
                    .Replace("alt", "")
                    .Replace("shift", "")
                    .Replace("ctrl", "")
                    .Replace("ctl", "");

                key = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(key);
                if (!string.IsNullOrEmpty(key))
                {
                    KeyConverter k = new KeyConverter();
                    kb.Key = (Key)k.ConvertFromString(key);
                }

                // Whatever command you need to bind to
                kb.Command = menuItem.Command;
                addin.Model.Window.InputBindings.Add(kb);
            }
        }
 private void EditInputBinding(MenuItem menu, ModifierKeys modifier) {
     KeyConverter k = new KeyConverter();
     Key key = (Key)k.ConvertFromString(menu.InputGestureText);
     InputBindingCollection InputBindingsCopy = new InputBindingCollection(InputBindings);
     foreach (KeyBinding item in InputBindingsCopy) {
         if (item.Key == key) {
             if (modifier == ModifierKeys.None)
                 InputBindings.Remove(item);
             else {
                 item.Modifiers = modifier;
                 if (modifier == ModifierKeys.Control)
                     menu.InputGestureText = "CTRL+" + menu.InputGestureText;
             }
             break;
         }
     }
 }