Beispiel #1
0
 private void BindHotkey(Key k, ModifierKeys m)
 {
     bindButton.Content = "bind key";
     UnregisterHotKey(handle, HOTKEY_ID);
     RegisterHotKey(handle, HOTKEY_ID, (uint)m, Convert.ToUInt32(VK_BINDING = KeyInterop.VirtualKeyFromKey(k)));
     stateBox.Text += "Bound hotkey: " + m.ToString() + " + " + k + "\n";
 }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            label2.Text = "on";

            bool whiletrue = true;

            while (whiletrue)
            {
                string status = Button.ModifierKeys.ToString();

                string str = Button.IsKeyLocked(Keys.CapsLock).ToString();

                string str1 = "";

                if ((str1 = ModifierKeys.ToString()) != "None")
                {
                    Console.WriteLine(str1);
                }

                if (IsKeyLocked(Keys.CapsLock))
                {
                    Console.WriteLine("Caps");
                }


                //Control.
            }
            label2.Text = "off";
        }
Beispiel #3
0
        public override string ToString()
        {
            String text = "";

            if (this.InputGestures.Count > 0)
            {
                KeyGesture   gesture  = (KeyGesture)this.InputGestures[0];
                Key          key      = gesture.Key;
                ModifierKeys modifier = gesture.Modifiers;

                if (modifier != ModifierKeys.None)
                {
                    text += modifier.ToString();
                }

                if (key != Key.None)
                {
                    if (text != "")
                    {
                        text += "+";
                    }
                    text += key.ToString();
                }
            }

            return(text);
        }
Beispiel #4
0
        private void AddForm_Load(object sender, EventArgs e)
        {
            if (!AllowFileEdit)
            {
                txtSound.Enabled = false;
                txtIcon.Enabled  = false;
                btnSound.Enabled = false;
                btnImage.Enabled = false;
            }

            txtSound.Text = sound;
            txtIcon.Text  = icon;

            string text = "";

            for (int i = 0; i < keys.Count; i++)
            {
                text += keys[i].ToString();

                if (i < keys.Count - 1)
                {
                    text += " + ";
                }
            }

            txtKey.Text                    = text;
            txtMod.Text                    = mods.ToString();
            trackVolume.Value              = (int)(Volume * 100);
            chkEcho.Checked                = UseEcho;
            trackEcho.Value                = (int)EchoAmount;
            trackEcho.Enabled              = UseEcho;
            rb_playmode_multi.Checked      = (Playmode == Event.PlayModes.multi);
            rb_playmode_once.Checked       = (Playmode == Event.PlayModes.once);
            rb_playmode_start_stop.Checked = (Playmode == Event.PlayModes.start_stop);
        }
Beispiel #5
0
        /// <summary>
        /// перехват нажимания кнопок
        /// </summary>
        /// <param name="key">Нажатая кнопка</param>
        void MainFormKeyPressedEvent(Keys key)
        {
            var mod = Enum.GetValues(typeof(Keys)).Cast <Keys>().Where(x => ModifierKeys.ToString().Split(',').Select(y => y.Trim()).Contains(x.ToString())).ToArray();

            curentMod1Key = mod.Length > 0 ? mod[0] : Keys.None;
            curentMod2Key = mod.Length > 1 ? mod[1] : Keys.None;


            if (key != Keys.ControlKey && key != Keys.ShiftKey)
            {
                ObjHotKey.mainKey = key;
                ObjHotKey.mod1    = curentMod1Key;
                ObjHotKey.mod2    = curentMod2Key;


                var sb = new StringBuilder(key.ToString());
                if (curentMod1Key != Keys.None && curentMod1Key != null)
                {
                    sb.Append(string.Format(" + {0}", curentMod1Key));
                    ObjHotKey.mod1 = curentMod1Key;
                }
                if (curentMod2Key != Keys.None && curentMod2Key != null)
                {
                    sb.Append(string.Format(" + {0}", curentMod2Key));
                    ObjHotKey.mod2 = curentMod2Key;
                }

                txtbxHotKeyNewValue.Text = sb.ToString();
            }
        }
Beispiel #6
0
        /// <summary>
        /// Get the string to represent ModKeys. This string removes any spaces that get
        /// injected by .NET (for compatibility with existing settings)
        /// </summary>
        /// <returns></returns>
        private string GetCleanModifierString()
        {
            if (ModKey == ModifierKeys.None)
            {
                return(string.Empty);
            }

            return(ModKey.ToString().Replace(" ", ""));
        }
        private static string GetDisplay(ModifierKeys modifierKeys, Key key)
        {
            var modifierDisplay = modifierKeys != ModifierKeys.None
                ? modifierKeys.ToString().Replace(",", "+").Replace(" ", "") + "+"
                : "";

            var keyDisplay = key != Key.None ? key.ToString() : "";

            return($"{modifierDisplay}{keyDisplay}");
        }
 public static IEnumerable <ModifierKeys> FlagsToList(this ModifierKeys flags)
 {
     return(flags.ToString()
            .Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)
            .Select(
                str =>
     {
         Enum.TryParse <ModifierKeys>(str, true, out var result);
         return result;
     }));
 }
        private void SetKeyAndModifier(ModifierKeys modifier, Keys key)
        {
            this.currentModifier = modifier;
            this.currentKey = key;
            string keyString = key.ToString();

            if (key == Keys.End)
                keyString = "End";

            command_box.Text = modifier.ToString() + " + " + keyString;
        }
Beispiel #10
0
        public override string ToString()
        {
            var sb = new StringBuilder();

            if (Modifiers != ModifierKeys.None)
            {
                sb.Append(Modifiers.ToString().Replace(", ", "+")).Append("+");
            }
            sb.Append(Key == Key.Undefined ? "Not Set" : Key.ToString());
            return(sb.ToString());
        }
Beispiel #11
0
 public override string ToString()
 {
     if (modifiers == ModifierKeys.None)
     {
         return(key.ToString());
     }
     else
     {
         return(key.ToString() + SEPARATOR_CHAR + modifiers.ToString());
     }
 }
Beispiel #12
0
            //--------------------------------------------------------------------------------------------------

            public string GetKeyString()
            {
                if (ModifierKeys != ModifierKeys.None)
                {
                    return($"{ModifierKeys.ToString()} + {Key.ToString()}");
                }
                else
                {
                    return(Key.ToString());
                }
            }
        public void SetCommandCombobox(ref System.Windows.Controls.ComboBox commandKeyCombobox,
                                       ref System.Windows.Controls.ComboBox commandModifierKeyCombobox,
                                       Keys commandKey, ModifierKeys commandModifierKey)
        {
            commandKeyCombobox.ItemsSource         = CommandKeys;
            commandModifierKeyCombobox.ItemsSource = ModifierKeys;
            var ctKey = CommandConstants.KeyNamesMap[commandKey];

            commandKeyCombobox.SelectedIndex         = CommandKeys.IndexOf(ctKey);
            commandModifierKeyCombobox.SelectedIndex =
                ModifierKeys.IndexOf(commandModifierKey.ToString());
        }
Beispiel #14
0
            override public string ToString()
            {
                string hotkeyStr = "";

                if (modifiers != ModifierKeys.None)
                {
                    hotkeyStr += modifiers.ToString().Replace(",", " +").Replace("Left", "").Replace("Right", "") + " + ";
                }
                hotkeyStr += key.ToString();
                hotkeyStr  = hotkeyStr.Replace("Oem", "");
                return(hotkeyStr);
            }
Beispiel #15
0
    /// <summary>
    /// Registers a hot key in the system.
    /// </summary>
    /// <param name="modifier">The modifiers that are associated with the hot key.</param>
    /// <param name="key">The key itself that is associated with the hot key.</param>
    public void RegisterHotKey(ModifierKeys modifier, Keys key)
    {
        //MessageBox.Show("Modifier: " + modifier.ToString() + "Key: "+ key.ToString());
        // increment the counter.
        _currentId = _currentId + 1;

        // register the hot key.
        if (!RegisterHotKey(_window.Handle, _currentId, (uint)modifier, (uint)key))
        {
            throw new InvalidOperationException("Unable to register the hotkey " + modifier.ToString() + " " + key.ToString() + ". Please choose a different one (or find the key or program that has registered it already).");
        }
    }
Beispiel #16
0
        public static string ToName(ModifierKeys modifierKeys, Key key)
        {
            string modifierkey_txt = modifierKeys == ModifierKeys.None ? string.Empty : modifierKeys.ToString(),
                   key_txt = key == Key.None ? string.Empty : key.ToString();

            var keyText = string.Format("{0}{1}{2}",
                modifierkey_txt,
                (modifierKeys == ModifierKeys.None || key == Key.None) ? string.Empty : ",", key_txt);

            keyText = keyText.Replace(",", " + ");

            return keyText;
        }
        private void SetKeyAndModifier(ModifierKeys modifier, Keys key)
        {
            this.currentModifier = modifier;
            this.currentKey      = key;
            string keyString = key.ToString();

            if (key == Keys.End)
            {
                keyString = "End";
            }

            command_box.Text = modifier.ToString() + " + " + keyString;
        }
Beispiel #18
0
        /// <summary>
        /// Get's the modifiers without a KeysEvent
        /// </summary>
        /// <returns></returns>
        private KeyModifiers GetWinModifiers()
        {
            KeyModifiers mods = new KeyModifiers();

            if (ModifierKeys != Keys.None)
            {
                //While doing this Mouse down, a key has also been held! for example, shift
                mods.ShiftKeyDown = ModifierKeys.ToString().ToLower().Contains(Keys.Shift.ToString().ToLower());
                mods.CtrlKeyDown  = ModifierKeys.ToString().ToLower().Contains(Keys.Control.ToString().ToLower());
                mods.AltKeyDown   = ModifierKeys.ToString().ToLower().Contains(Keys.Alt.ToString().ToLower());
            }
            return(mods);
        }
Beispiel #19
0
        public override string ToString()
        {
            if (!Enabled)
            {
                return("");
            }

            if (ModifierKeys == ModifierKeys.None)
            {
                return(Key.ToString());
            }
            return(ModifierKeys.ToString().Replace(", ", " + ").Replace("Control", "Ctrl") + " + " + Key.ToString());
        }
        /// <summary>
        /// Handles key down event. Stores modifier or key. Exits dialog
        /// if appropriate
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            Key tempKey = (e.Key == Key.System ? e.SystemKey : e.Key);

            switch (tempKey)
            {
            case Key.Escape:
                return;

            case Key.LeftAlt:
            case Key.RightAlt:
                ModKey |= ModifierKeys.Alt;
                break;

            case Key.LeftCtrl:
            case Key.RightCtrl:
                ModKey |= ModifierKeys.Control;
                break;

            case Key.LeftShift:
            case Key.RightShift:
                ModKey |= ModifierKeys.Shift;
                break;

            case Key.LWin:
            case Key.RWin:
                ModKey |= ModifierKeys.Windows;
                break;

            default:
                SelectedKey = tempKey;
                break;
            }

            if (ModKey != ModifierKeys.None)
            {
                this.lbModifiers.Content = ModKey.ToString();
            }

            if (SelectedKey != Key.None)
            {
                this.lbKey.Content = GetCleanKeyString();
            }

            if (ModKey != ModifierKeys.None && SelectedKey != Key.None)
            {
                ButtonParent.Content = string.Format(CultureInfo.InvariantCulture, "{0} + {1}", ModKey.ToString(), GetCleanKeyString());
                this.Close();
            }
        }
Beispiel #21
0
        /// <summary>
        /// Gets a display string representing a <see cref="ModifierKeys"/> and
        /// <see cref="Keys"/> pair suitable for display in the UI.
        /// </summary>
        public static string GetFriendlyName(ModifierKeys modifierKeys, Keys primaryKey)
        {
            string displayText = "";

            if (primaryKey != Keys.None)
            {
                if (modifierKeys != ModifierKeys.None)
                {
                    displayText = $"{modifierKeys.ToString().Replace(", ", " + ")} + ";
                }

                displayText += GetFriendlyName(primaryKey);
            }

            return(displayText);
        }
Beispiel #22
0
 public AddProgram(string id, string ProgramName, string ProgramPath, string ProgramArgs, Key AN, ModifierKeys Mod1, ModifierKeys Mod2)
 {
     InitializeComponent();
     IsEditMode          = true;
     appid               = id;
     btnDelete.IsEnabled = true;
     this.Title          = "Edit";
     txtProgramName.Text = ProgramName;
     txtProgramPath.Text = ProgramPath;
     txtProgramArgs.Text = ProgramArgs;
     this.AN             = AN;
     txtANKey.Text       = AN.ToString();
     this.Mod1           = Mod1;
     txtModKey1.Text     = Mod1.ToString();
     this.Mod2           = Mod2;
     txtModKey2.Text     = Mod2.ToString();
 }
Beispiel #23
0
        private void txtMod_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Modifiers == Keys.None)
            {
                return;
            }

            if (modready)
            {
                modready = false;
                mods     = Sound_events.ModifierKeys.None;
            }

            ModifierKeys modifier = (ModifierKeys)Enum.Parse(typeof(ModifierKeys), e.Modifiers.ToString());

            mods        = modifier;
            txtMod.Text = mods.ToString();
        }
Beispiel #24
0
        private void ConfigureKey(string inputKey, KeyBinding keyBinding, MenuItem menuItem)
        {
            if (this.UserConfig["key_bindings"].ContainsKey(inputKey + "_modifiers"))
            {
                ModifierKeys modifierKeys = Utils.StringToKeyEnum <ModifierKeys>(this.UserConfig["key_bindings"][inputKey + "_modifiers"]);
                keyBinding.Modifiers              = modifierKeys;
                MainWnd.SaveBtn.InputGestureText += modifierKeys.ToString();
            }
            else
            {
                keyBinding.Modifiers      = this.DefaultModifier;
                menuItem.InputGestureText = this.DefaultModifier.ToString();
            }

            Key key = Utils.StringToKeyEnum <Key>(this.UserConfig["key_bindings"][inputKey]);

            keyBinding.Key             = key;
            menuItem.InputGestureText += $"+{ key.ToString() }";
        }
Beispiel #25
0
        private static string KeysToString(ModifierKeys mods, Keys keys)
        {
            string ans = "";

            for (int n = 1; n <= 8; n <<= 1)
            {
                ModifierKeys m = (ModifierKeys)n;
                if (mods.HasFlag(m))
                {
                    ans += $" + {m.ToString()}";
                }
            }
            ans += $" + {keys.ToString()}";
            if (ans.Length > 0)
            {
                ans = ans.Substring(" + ".Length);
            }
            return(ans);
        }
Beispiel #26
0
        /// <summary>
        /// Search for keypress to write it in textbox
        /// Search for modifiers to stop double writing -> Control + Control
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HotKeyTextBox_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            string keysPressed;

            if (e.Alt || e.Control || e.Shift)
            {
                keysPressed = ModifierKeys + " + " + e.KeyCode.ToString();
                string[] removingModifiers = keysPressed.Split('+');
                if (removingModifiers[1].Contains(Keys.Alt.ToString()) || removingModifiers[1].Contains(Keys.Shift.ToString()) || removingModifiers[1].Contains(Keys.Control.ToString()) || removingModifiers[1].Contains("Menu"))
                {
                    HotKeyTextBox.Text = ModifierKeys.ToString();
                }
                else
                {
                    HotKeyTextBox.Text = keysPressed;
                }
            }
            else
            {
                HotKeyTextBox.Text = e.KeyCode.ToString();
            }
        }
        public void SetShortcut(IStaticPanelDefinition definition, ModifierKeys modifierKeys, Key key)
        {
            definition.AssertParameterNotNull(nameof(definition));
            if (!PanelManager.IsRegistered(definition))
            {
                throw new Exception("Error : Cannot set the BringIntoView shortcut for the specified static panel definition : The definition is not registered in the panel manager.");
            }

            if (!LoadingScope.IsInScope)
            {
                var matchingElements = GetElementsMatchingShortcut(modifierKeys, key).Where(o => !(o == definition));
                if (matchingElements.Any())
                {
                    throw new Exception($"Error setting the shortcut {modifierKeys.ToString()}+{key.ToString()} on command {GetElementName(definition)} " +
                                        $"because element(s) {string.Join(",", matchingElements.Select(o => GetElementName(o)))} already have a shortcut with the same " +
                                        $"key combination.");
                }
            }

            if (HasShortcut(definition))
            {
                var shortcut = GetShortcut(definition);
                if (shortcut.ModifierKeys == modifierKeys && shortcut.Key == key)
                {
                    return;
                }
                shortcut.ModifierKeys = modifierKeys;
                shortcut.Key          = key;
            }
            else
            {
                var metadataCollection = definition as MetadataCollection <IStaticPanelMetadata>;
                metadataCollection.Add(new BringIntoViewOnKeyShortcut(modifierKeys, key));
            }

            NotifyPanelShortcutsChanged(definition);
        }
        public void SetShortcut(IGlobalCommand command, ModifierKeys modifierKeys, Key key)
        {
            command.AssertParameterNotNull(nameof(command));
            if (!CommandManager.IsRegistered(command))
            {
                throw new Exception("Error : Cannot set the shortcut for the specified command : The command is not registered in the command manager.");
            }

            if (!LoadingScope.IsInScope)
            {
                var matchingElements = GetElementsMatchingShortcut(modifierKeys, key).Where(o => !(o == command));
                if (matchingElements.Any())
                {
                    throw new Exception($"Error setting the shortcut {modifierKeys.ToString()}+{key.ToString()} on command {GetElementName(command)} " +
                                        $"because element(s) {string.Join(",", matchingElements.Select(o => GetElementName(o)))} already have a shortcut with the same " +
                                        $"key combination.");
                }
            }

            if (HasShortcut(command))
            {
                var shortcut = GetShortcut(command);
                if (shortcut.ModifierKeys == modifierKeys && shortcut.Key == key)
                {
                    return;
                }
                shortcut.ModifierKeys = modifierKeys;
                shortcut.Key          = key;
            }
            else
            {
                command.Metadata.Add(new KeyShortcut(modifierKeys, key));
            }

            NotifyCommandShortcutsChanged(command);
        }
Beispiel #29
0
 public static void SetKeyModifierStart(ModifierKeys mods)
 {
     toggl_set_key_modifier_start(ctx, mods.ToString());
 }
Beispiel #30
0
 public static void SetKeyModifierStart(ModifierKeys mods)
 {
     toggl_set_key_modifier_start(ctx, mods.ToString());
 }
Beispiel #31
0
        public static string ToName(ModifierKeys modifierKeys, Key key)
        {
            string modifierkey_txt = modifierKeys == ModifierKeys.None ? string.Empty : modifierKeys.ToString(),
                   key_txt         = key == Key.None ? string.Empty : key.ToString();

            var keyText = string.Format("{0}{1}{2}",
                                        modifierkey_txt,
                                        (modifierKeys == ModifierKeys.None || key == Key.None) ? string.Empty : ",", key_txt);

            keyText = keyText.Replace(",", " + ");

            return(keyText);
        }
 private void UpdateButtonText()
 {
     HotkeyButton.Text = Modifiers.ToString("G").Replace(",", " +").Replace("Control", "Ctrl") + " + " + (Capturing ? "..." : Key.ToString("G"));
 }
Beispiel #33
0
    /// <summary>
    /// Registers a hot key in the system.
    /// </summary>
    /// <param name="modifier">The modifiers that are associated with the hot key.</param>
    /// <param name="key">The key itself that is associated with the hot key.</param>
    public void RegisterHotKey(ModifierKeys modifier, Keys key)
    {
        //MessageBox.Show("Modifier: " + modifier.ToString() + "Key: "+ key.ToString());
        // increment the counter.
        _currentId = _currentId + 1;

        // register the hot key.
        if (!RegisterHotKey(_window.Handle, _currentId, (uint)modifier, (uint)key))
            throw new InvalidOperationException("Unable to register the hotkey " + modifier.ToString() + " "+ key.ToString() + ". Please choose a different one (or find the key or program that has registered it already).");
    }
Beispiel #34
0
        /// <summary>
        /// Registers a hot key in the system.
        /// </summary>
        /// <param name="modifier">The modifiers that are associated with the hot key.</param>
        /// <param name="key">The key itself that is associated with the hot key.</param>
        public void RegisterHotKey(ModifierKeys modifier, Keys key)
        {
            // increment the counter.
            _currentId = _currentId + 1;

            // register the hot key.
            if (!RegisterHotKey(_window.Handle, _currentId, (uint)modifier, (uint)key))
            {
                throw new InvalidOperationException("### Couldn’t register the hot key: " + modifier.ToString() + " | " + key.ToString());
            }
        }