Exemple #1
0
        private void Launcher_KeyUp(object sender, KeyEventArgs e)
        {
            if (Keyboard.IsKeyUp(Key.LeftShift) || Keyboard.IsKeyUp(Key.RightShift))
            {
                IsShiftDown = false;
            }

            IInputElement focused = FocusManager.GetFocusedElement(this);

            if (focused is TextBox)
            {
                TextBox target = focused as TextBox;
                if (target.Name == "ConsoleCommandTextBox")
                {
                    object     context    = target.DataContext;
                    Executable executable = (context is Executable) ? context as Executable : null;
                    if (executable is null || !executable.AllowCommands)
                    {
                        return;
                    }

                    if (e.Key == Key.Enter)
                    {
                        executable.Write();
                    }
                    if (e.Key == Key.Up)
                    {
                        executable.PreviousHistoryCommand();
                        target.CaretIndex = target.Text.Length;
                    }
                    if (e.Key == Key.Down)
                    {
                        executable.NextHistoryCommand();
                        target.CaretIndex = target.Text.Length;
                    }
                }
            }
        }