Esempio n. 1
0
        private void textBox_hotKey_KeyDown(object sender, KeyEventArgs e)
        {
            var textBox = sender as TextBox;

            if (textBox == null)
            {
                return;
            }
            if (textBox.Tag == null)
            {
                return;
            }

            e.SuppressKeyPress = true;
            if (e.KeyCode != Keys.Escape && !InvalidateHotKey(e.Modifiers, e.KeyCode))
            {
                return;
            }

            var tmp = HotKey.CreateTemplate(e.Modifiers, e.KeyCode);

            if (e.KeyCode != Keys.Escape)
            {
                var addeds = CaptureSetting.HotKeys.Where(o => o.Value.Modifiers == tmp.Modifiers && o.Value.Key == tmp.Key);
                foreach (var added in addeds)
                {
                    if (added.Value == tmp)
                    {
                        continue;
                    }

                    added.Value.Update(WindowNative.KeyModifiers.None, Keys.None);

                    var owner = _textBoxs.FirstOrDefault(o => (CaptureMode)o.Tag == added.Key);
                    if (owner != null)
                    {
                        owner.Text = added.Value.ToString();
                    }
                }
            }

            var mode   = (CaptureMode)textBox.Tag;
            var hotKey = CaptureSetting.HotKeys[mode];

            hotKey.Update(tmp.Modifiers, tmp.Key);
            textBox.Text = tmp.ToString();
        }