Ejemplo n.º 1
0
        protected override void OnKeyUp(KeyEventArgs e)
        {
            Keys modifierKeys = e.Modifiers;
            Keys pressedKey   = e.KeyData ^ modifierKeys;

            if (modifierKeys != Keys.None && !HotkeyJustSet)
            {
                Text = "";
                if ((modifierKeys & Keys.Control) > 0)
                {
                    Text += LocalSt.KeyNames[0x00020000] + " + ";
                }
                if ((modifierKeys & Keys.Alt) > 0)
                {
                    Text += LocalSt.KeyNames[0x00040000] + " + ";
                }
                if ((modifierKeys & Keys.Shift) > 0)
                {
                    Text += LocalSt.KeyNames[0x00010000] + " + ";
                }
                if ((modifierKeys & Keys.LWin) > 0 || (modifierKeys & Keys.RWin) > 0)
                {
                    Text += LocalSt.KeyNames[0x5B] + " + ";
                }

                if (Hotkey.IsValidKey(pressedKey))
                {
                    Text += LocalSt.KeyNames[(int)pressedKey];
                }
            }

            if (modifierKeys == Keys.None)
            {
                UpdateText();
                _InWaitingKey = false;
                SetBackColor();
                HotkeyJustSet = false;
            }
        }
Ejemplo n.º 2
0
        protected override void OnKeyUp(KeyEventArgs e)
        {
            Keys modifierKeys = e.Modifiers;
            Keys pressedKey   = e.KeyData ^ modifierKeys;

            if (modifierKeys != Keys.None && !HotkeyJustSet)
            {
                Text = "";
                if ((modifierKeys & Keys.Control) > 0)
                {
                    Text += "Ctrl + ";
                }
                if ((modifierKeys & Keys.Alt) > 0)
                {
                    Text += "Alt + ";
                }
                if ((modifierKeys & Keys.Shift) > 0)
                {
                    Text += "Shift + ";
                }
                if ((modifierKeys & Keys.LWin) > 0 || (modifierKeys & Keys.RWin) > 0)
                {
                    Text += "Win + ";
                }

                if (Hotkey.IsValidKey(pressedKey))
                {
                    Text += pressedKey.ToString();
                }
            }

            if (modifierKeys == Keys.None)
            {
                UpdateText();
                _InWaitingKey = false;
                SetBackColor();
                HotkeyJustSet = false;
            }
        }
Ejemplo n.º 3
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            e.SuppressKeyPress = true;

            Keys modifierKeys = e.Modifiers;
            Keys pressedKey   = e.KeyData ^ modifierKeys;

            //bool deleting = pressedKey == Keys.Escape || pressedKey == Keys.Delete || pressedKey == Keys.Back;
            bool deleting = pressedKey == Keys.Delete || pressedKey == Keys.Back;

            if (deleting)
            {
                Text = "None";
            }
            else
            {
                Text = "";
                if ((modifierKeys & Keys.Control) > 0)
                {
                    Text += "Ctrl + ";
                }
                if ((modifierKeys & Keys.Alt) > 0)
                {
                    Text += "Alt + ";
                }
                if ((modifierKeys & Keys.Shift) > 0)
                {
                    Text += "Shift + ";
                }
                if ((modifierKeys & Keys.LWin) > 0 || (modifierKeys & Keys.RWin) > 0)
                {
                    Text += "Win + ";
                }

                if (Hotkey.IsValidKey(pressedKey))
                {
                    Text += pressedKey.ToString();
                }
            }

            if (deleting)
            {
                Hotkey.Key     = 0;
                Hotkey.Control = false;
                Hotkey.Alt     = false;
                Hotkey.Shift   = false;
                Hotkey.Win     = false;
                HotkeyJustSet  = true;
                _InWaitingKey  = false;
                SetBackColor();
                if (OnHotkeyChanged != null)
                {
                    OnHotkeyChanged(this, null);
                }
            }
            else if ((!RequireModifier || modifierKeys != Keys.None) && Hotkey.IsValidKey(pressedKey))
            {
                Hotkey.Key     = (int)pressedKey;
                Hotkey.Control = (modifierKeys & Keys.Control) > 0;
                Hotkey.Alt     = (modifierKeys & Keys.Alt) > 0;
                Hotkey.Shift   = (modifierKeys & Keys.Shift) > 0;
                Hotkey.Win     = (modifierKeys & Keys.LWin) > 0 || (modifierKeys & Keys.RWin) > 0;
                HotkeyJustSet  = true;
                _InWaitingKey  = false;
                SetBackColor();
                if (OnHotkeyChanged != null)
                {
                    OnHotkeyChanged(this, null);
                }
            }
            else
            {
                _InWaitingKey = true;
                SetBackColor();
            }
        }
Ejemplo n.º 4
0
        protected override void OnPreviewKeyDown(PreviewKeyDownEventArgs e)
        {
            e.IsInputKey = true;
            base.OnPreviewKeyDown(e);

            Keys modifierKeys = e.Modifiers;
            Keys pressedKey   = e.KeyData ^ modifierKeys;

            //bool deleting = pressedKey == Keys.Escape || pressedKey == Keys.Delete || pressedKey == Keys.Back;
            bool deleting = ((modifierKeys & Keys.Control) > 0) && ((modifierKeys & Keys.Shift) > 0) && (pressedKey == Keys.Delete || pressedKey == Keys.Back);

            if (deleting)
            {
                Text = LocalSt.KeyNames[0];
            }
            else
            {
                Text = "";
                if ((modifierKeys & Keys.Control) > 0)
                {
                    Text += LocalSt.KeyNames[0x00020000] + " + ";
                }
                if ((modifierKeys & Keys.Alt) > 0)
                {
                    Text += LocalSt.KeyNames[0x00040000] + " + ";
                }
                if ((modifierKeys & Keys.Shift) > 0)
                {
                    Text += LocalSt.KeyNames[0x00010000] + " + ";
                }
                if ((modifierKeys & Keys.LWin) > 0 || (modifierKeys & Keys.RWin) > 0)
                {
                    Text += LocalSt.KeyNames[0x5B] + " + ";
                }

                if (Hotkey.IsValidKey(pressedKey))
                {
                    Text += LocalSt.KeyNames[(int)pressedKey];
                }
            }

            if (deleting)
            {
                Hotkey.Key     = 0;
                Hotkey.Control = false;
                Hotkey.Alt     = false;
                Hotkey.Shift   = false;
                Hotkey.Win     = false;
                HotkeyJustSet  = true;
                _InWaitingKey  = false;
                SetBackColor();
                if (OnHotkeyChanged != null)
                {
                    OnHotkeyChanged(this, null);
                }
            }
            else if ((!RequireModifier || modifierKeys != Keys.None) && Hotkey.IsValidKey(pressedKey))
            {
                Hotkey.Key     = (int)pressedKey;
                Hotkey.Control = (modifierKeys & Keys.Control) > 0;
                Hotkey.Alt     = (modifierKeys & Keys.Alt) > 0;
                Hotkey.Shift   = (modifierKeys & Keys.Shift) > 0;
                Hotkey.Win     = (modifierKeys & Keys.LWin) > 0 || (modifierKeys & Keys.RWin) > 0;
                HotkeyJustSet  = true;
                _InWaitingKey  = false;
                SetBackColor();
                if (OnHotkeyChanged != null)
                {
                    OnHotkeyChanged(this, null);
                }
            }
            else
            {
                _InWaitingKey = true;
                SetBackColor();
            }
        }