Exemplo n.º 1
0
        private void HotkeyInput(object sender, KeyEventArgs e)
        {
            string hotkeyString;

            e.SuppressKeyPress = true;
            TextBox keyTxtBox = sender as TextBox;
            Keys    keyCode   = e.KeyCode;

            if (keyCode != Keys.ControlKey && keyCode != Keys.Menu && keyCode != Keys.ShiftKey)
            {
                if (keyCode == Keys.Escape || keyCode == Keys.LWin || keyCode == Keys.RWin)
                {
                    keyTxtBox.Text = "";
                }
                else
                {
                    if (keyTxtBox.Name == "keyToPressTxtBox")
                    {
                        hotkeyString = keysTranslater.KeyCodeToString(keyCode);
                    }
                    else
                    {
                        hotkeyString = (e.Control ? "CTRL+" : "") + (e.Alt ? "ALT+" : "") + (e.Shift ? "SHIFT+" : "") + keysTranslater.KeyCodeToString(keyCode);
                    }
                    foreach (TextBox txtBox in this.GetAll(typeof(TextBox)))
                    {
                        if (txtBox.Text == hotkeyString)
                        {
                            txtBox.Text = "";
                        }
                    }
                    keyTxtBox.Text = hotkeyString;
                }
            }
        }
Exemplo n.º 2
0
        private XElement SaveControlHotkeyToXml(ControlHotkey hotkey)
        {
            XElement     xmlHotkey = new XElement("ControlHotkey", new XElement("Key", hotkey.Key.FullKeyString));
            XElement     ctrlData  = null;
            ControlRoles ctrlRole  = hotkey.Role;

            xmlHotkey.Add(new XElement("Role", ctrlRole.ToString()));
            switch (ctrlRole)
            {
            case ControlRoles.HoldDownKey:
                ctrlData = new XElement("PressWhichKey", keysTranslater.KeyCodeToString((hotkey.HoldDownKey)));
                break;

            case ControlRoles.Forward:
            case ControlRoles.Backward:
            case ControlRoles.IncreaseVolume:
            case ControlRoles.DecreaseVolume:
            case ControlRoles.IncreasePitch:
            case ControlRoles.DecreasePitch:
            case ControlRoles.IncreaseTempo:
            case ControlRoles.DecreaseTempo:
            case ControlRoles.IncreaseSpeed:
            case ControlRoles.DecreaseSpeed:
                ctrlData = new XElement("FlowChangeValue", hotkey.FlowChangeValue.ToString());
                break;
            }
            if (ctrlData != null)
            {
                xmlHotkey.Add(ctrlData);
            }
            return(xmlHotkey);
        }
Exemplo n.º 3
0
        public string RemapKey(string fullkey, short originalLayoutIdentifier)
        {
            KeyAndModifiers key         = new KeyAndModifiers(fullkey);
            string          remappedKey = key.ModifiersString + keysTranslater.KeyCodeToString(keysTranslater.ReMapKey(originalLayoutIdentifier, key.KeyString));

            if (remappedKey == "Keys.None" || remappedKey == "None")
            {
                throw new KeyRemappingFailedException(fullkey, originalLayoutIdentifier);
            }
            return(remappedKey);
        }