示例#1
0
        internal KeyInputEditControl(KeyInputControl control)
        {
            InitializeComponent();

            // Use a lambda here so we can capture the 'control' variable
            // only for as long as needed to set our location/size.
            Load += (object sender, EventArgs e) =>
            {
                Location = control.Parent.PointToScreen(control.Location);
                Size     = control.Size;
                textBox.Focus();
                HookKeyboard();
            };

            FormClosed += (object sender, FormClosedEventArgs e) =>
            {
                UnhookKeyboard();
            };

            liveInput  = control.UserInput;
            isModifier = liveInput.IsModifier;

#pragma warning disable IDE0008 // Use explicit type
            var input = UserCommandInput.DecomposeUniqueDescriptor(liveInput.UniqueDescriptor);
#pragma warning restore IDE0008 // Use explicit type
            shift        = input.Shift;
            this.control = input.Control;
            alt          = input.Alt;
            scanCode     = input.ScanCode;
            virtualKey   = (Xna.Keys)input.VirtualKey;

            UpdateText();
        }
示例#2
0
        public KeyInputControl(UserCommandInput userInput, UserCommandInput defaultInput)
        {
            InitializeComponent();

            UserInput    = userInput;
            DefaultInput = defaultInput;
            UpdateText();
        }
示例#3
0
        /// <summary>
        /// return whether the key belonging to the given command is down
        /// </summary>
        /// <param name="command">The command (a key-combination should have been defined for the command)</param>
        public static bool IsDown(TVUserCommands command)
        {
            //if (ComposingMessage == true) return false;
            //if (RDState != null && RDState.IsDown(command))
            //    return true;
            UserCommandInput setting = TVInputSettings.Commands[(int)command];

            return(setting.IsKeyDown(KeyboardState));
        }
示例#4
0
        public KeyInputEditControl(KeyInputControl control)
        {
            InitializeComponent();

            // Windows 2000 and XP should use 8.25pt Tahoma, while Windows
            // Vista and later should use 9pt "Segoe UI". We'll use the
            // Message Box font to allow for user-customizations, though.
            Font = SystemFonts.MessageBoxFont;

            // Use a lambda here so we can capture the 'control' variable
            // only for as long as needed to set our location/size.
            Load += (object sender, EventArgs e) =>
            {
                Location = control.Parent.PointToScreen(control.Location);
                Size     = control.Size;
                textBox.Focus();
                HookKeyboard();
            };

            FormClosed += (object sender, FormClosedEventArgs e) =>
            {
                UnhookKeyboard();
            };

            LiveInput  = control.UserInput;
            IsModifier = LiveInput.IsModifier;
            var parts = LiveInput.PersistentDescriptor.Split(',');

            if (parts.Length >= 5)
            {
                ScanCode   = int.Parse(parts[0]);
                VirtualKey = (Xna.Keys) int.Parse(parts[1]);
                Shift      = parts[2] != "0";
                Control    = parts[3] != "0";
                Alt        = parts[4] != "0";
            }
            UpdateText();
        }
示例#5
0
        public KeyInputEditControl(KeyInputControl control)
        {
            InitializeComponent();

            // Windows 2000 and XP should use 8.25pt Tahoma, while Windows
            // Vista and later should use 9pt "Segoe UI". We'll use the
            // Message Box font to allow for user-customizations, though.
            Font = SystemFonts.MessageBoxFont;

            // Use a lambda here so we can capture the 'control' variable
            // only for as long as needed to set our location/size.
            Load += (object sender, EventArgs e) =>
            {
                Location = control.Parent.PointToScreen(control.Location);
                Size     = control.Size;
                textBox.Focus();
                HookKeyboard();
            };

            FormClosed += (object sender, FormClosedEventArgs e) =>
            {
                UnhookKeyboard();
            };

            LiveInput  = control.UserInput;
            IsModifier = LiveInput.IsModifier;

            var input = UserCommandInput.DecomposeUniqueDescriptor(LiveInput.UniqueDescriptor);

            Shift      = input.Shift;
            Control    = input.Control;
            Alt        = input.Alt;
            ScanCode   = input.ScanCode;
            VirtualKey = (Xna.Keys)input.VirtualKey;

            UpdateText();
        }
示例#6
0
 private void UpdateText()
 {
     liveInput.UniqueDescriptor = UserCommandInput.ComposeUniqueDescriptor(shift, control, alt, scanCode, virtualKey);
     textBox.Text = liveInput.ToString();
 }
示例#7
0
 private void UpdateText()
 {
     LiveInput.UniqueDescriptor = UserCommandInput.ComposeUniqueDescriptor(Shift, Control, Alt, ScanCode, VirtualKey);
     textBox.Text = LiveInput.ToString();
 }
示例#8
0
        public string CheckForErrors()
        {
            // Make sure all modifiable input commands are synchronized first.
            foreach (UserCommandInput command in UserCommands)
            {
                (command as UserCommandModifiableKeyInput)?.SynchronizeCombine();
            }

            StringBuilder errors = new StringBuilder();

            // Check for commands which both require a particular modifier, and ignore it.
            foreach (UserCommand command in EnumExtension.GetValues <UserCommand>())
            {
                if (UserCommands[command] is UserCommandModifiableKeyInput modInput)
                {
                    if (modInput.Shift && modInput.IgnoreShift)
                    {
                        errors.AppendLine(catalog.GetString("{0} requires and is modified by Shift", commonCatalog.GetString(command.GetDescription())));
                    }
                    if (modInput.Control && modInput.IgnoreControl)
                    {
                        errors.AppendLine(catalog.GetString("{0} requires and is modified by Control", commonCatalog.GetString(command.GetDescription())));
                    }
                    if (modInput.Alt && modInput.IgnoreAlt)
                    {
                        errors.AppendLine(catalog.GetString("{0} requires and is modified by Alt", commonCatalog.GetString(command.GetDescription())));
                    }
                }
            }

            // Check for two commands assigned to the same key
            UserCommand firstCommand = EnumExtension.GetValues <UserCommand>().Min();
            UserCommand lastCommand  = EnumExtension.GetValues <UserCommand>().Max();

            for (UserCommand command1 = firstCommand; command1 <= lastCommand; command1++)
            {
                UserCommandInput input1 = UserCommands[command1];

                // Modifier inputs don't matter as they don't represent any key.
                if (input1 is UserCommandModifierInput)
                {
                    continue;
                }

                for (UserCommand command2 = command1 + 1; command2 <= lastCommand; command2++)
                {
                    UserCommandInput input2 = UserCommands[command2];

                    // Modifier inputs don't matter as they don't represent any key.
                    if (input2 is UserCommandModifierInput)
                    {
                        continue;
                    }

                    // Ignore problems when both inputs are on defaults. (This protects the user somewhat but leaves developers in the dark.)
                    if (input1.UniqueDescriptor == DefaultCommands[command1].UniqueDescriptor &&
                        input2.UniqueDescriptor == DefaultCommands[command2].UniqueDescriptor)
                    {
                        continue;
                    }

                    IEnumerable <string> unique1      = input1.GetUniqueInputs();
                    IEnumerable <string> unique2      = input2.GetUniqueInputs();
                    IEnumerable <string> sharedUnique = unique1.Where(id => unique2.Contains(id));
                    foreach (string uniqueInput in sharedUnique)
                    {
                        errors.AppendLine(catalog.GetString("{0} and {1} both match {2}", commonCatalog.GetString(command1.GetDescription()),
                                                            commonCatalog.GetString(command2.GetDescription()), KeyboardMap.GetPrettyUniqueInput(uniqueInput)));
                    }
                }
            }

            return(errors.ToString());
        }