示例#1
0
        private void InputBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                string consoleBeforeCall = OutputBox.Text;

                // TODO: Maybe make these try-catches more general
                if (!string.IsNullOrWhiteSpace(InputBox.Text))
                {
                    if (InputBox.Text.Contains("emu.frameadvance("))
                    {
                        ConsoleLog("emu.frameadvance() can not be called from the console");
                        return;
                    }

                    LuaSandbox.Sandbox(null, () =>
                    {
                        LuaImp.ExecuteString($"console.log({InputBox.Text})");
                    }, () =>
                    {
                        LuaSandbox.Sandbox(null, () =>
                        {
                            LuaImp.ExecuteString(InputBox.Text);

                            if (OutputBox.Text == consoleBeforeCall)
                            {
                                ConsoleLog("Command successfully executed");
                            }
                        });
                    });

                    _consoleCommandHistory.Insert(0, InputBox.Text);
                    _consoleCommandHistoryIndex = -1;
                    InputBox.Clear();
                }
            }
            else if (e.KeyCode == Keys.Up)
            {
                if (_consoleCommandHistoryIndex < _consoleCommandHistory.Count - 1)
                {
                    _consoleCommandHistoryIndex++;
                    InputBox.Text = _consoleCommandHistory[_consoleCommandHistoryIndex];
                    InputBox.Select(InputBox.Text.Length, 0);
                }

                e.Handled = true;
            }
            else if (e.KeyCode == Keys.Down)
            {
                if (_consoleCommandHistoryIndex == 0)
                {
                    _consoleCommandHistoryIndex--;
                    InputBox.Text = "";
                }
                else if (_consoleCommandHistoryIndex > 0)
                {
                    _consoleCommandHistoryIndex--;
                    InputBox.Text = _consoleCommandHistory[_consoleCommandHistoryIndex];
                    InputBox.Select(InputBox.Text.Length, 0);
                }

                e.Handled = true;
            }
            else if (e.KeyCode == Keys.Tab)
            {
                ProcessTabKey(false);
                e.Handled = true;
            }
        }
示例#2
0
        private void InputBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                string consoleBeforeCall = OutputBox.Text;

                // TODO: Maybe make these try-catches more general
                if (InputBox.Text != "")
                {
                    LuaSandbox.Sandbox(null, () =>
                    {
                        LuaImp.ExecuteString(string.Format("console.log({0})", InputBox.Text));
                    }, () =>
                    {
                        LuaSandbox.Sandbox(null, () =>
                        {
                            LuaImp.ExecuteString(InputBox.Text);

                            if (OutputBox.Text == consoleBeforeCall)
                            {
                                ConsoleLog("Command successfully executed");
                            }
                        });
                    });

                    _consoleCommandHistory.Insert(0, InputBox.Text);
                    _consoleCommandHistoryIndex = -1;
                    InputBox.Clear();
                }
            }
            else if (e.KeyCode == Keys.Up)
            {
                if (_consoleCommandHistoryIndex < _consoleCommandHistory.Count - 1)
                {
                    _consoleCommandHistoryIndex++;
                    InputBox.Text = _consoleCommandHistory[_consoleCommandHistoryIndex];
                    InputBox.Select(InputBox.Text.Length, 0);
                }
                e.Handled = true;
            }
            else if (e.KeyCode == Keys.Down)
            {
                if (_consoleCommandHistoryIndex == 0)
                {
                    _consoleCommandHistoryIndex--;
                    InputBox.Text = "";
                }
                else if (_consoleCommandHistoryIndex > 0)
                {
                    _consoleCommandHistoryIndex--;
                    InputBox.Text = _consoleCommandHistory[_consoleCommandHistoryIndex];
                    InputBox.Select(InputBox.Text.Length, 0);
                }
                e.Handled = true;
            }
            else if (e.KeyCode == Keys.Tab)
            {
                this.ProcessTabKey(false);
                e.Handled = true;
            }
        }