private void richTextBoxConsole_KeyDown(object sender, KeyEventArgs e) {
// Are we sending keyboard commands to the process?
if (SendKeyboardCommandsToProcess && IsProcessRunning) {
richTextBoxConsole.SelectionColor = Color.White;
// Get key mappings for this key event?
var mappings = from k in keyMappings
where
k.KeyCode == e.KeyCode &&
k.IsAltPressed == e.Alt &&
k.IsControlPressed == e.Control &&
k.IsShiftPressed == e.Shift
select k;
if (e.KeyCode == Keys.Tab)
{
SendTab(processInterace.Process.MainWindowHandle);
// SendKeysEx.SendKeys(this._cmdhandle, "{TAB}");
}
//// Go through each mapping, send the message.
//foreach (var mapping in mappings) { //TODO: Find out if we need this [For Each]
// //SendKeysEx.SendKeys(this._cmdhandle, mapping.SendKeysMapping);
// //WriteInput(mapping.StreamMapping, Color.Yellow);
// //WriteInput("\x3", Color.White);
//}
// If we handled a mapping, we're done here.
if (mappings.Any()) {
e.SuppressKeyPress = true;
return;
}
}
// If we're at the input point and it's backspace, bail.
if ((richTextBoxConsole.SelectionStart <= inputStart) && e.KeyCode == Keys.Back) e.SuppressKeyPress = true;
// Are we in the read-only zone?
if (richTextBoxConsole.SelectionStart < inputStart) {
// Allow arrows and Ctrl-C.
if (!(e.KeyCode == Keys.Left ||
e.KeyCode == Keys.Right ||
e.KeyCode == Keys.Up ||
e.KeyCode == Keys.Down ||
(e.KeyCode == Keys.C && e.Control))) {
e.SuppressKeyPress = true;
}
if (e.KeyData == (Keys.C | Keys.ControlKey))
MessageBox.Show("CTRL");
//if (e.KeyCode == Keys.C)
//{
// MessageBox.Show(richTextBoxConsole.SelectedText);
// Clipboard.SetText(richTextBoxConsole.SelectedText);
//}
}
// Is it the return key?
if (e.KeyCode == Keys.Return) {
this._ShouldClear = false;
// Get the input.
string input = richTextBoxConsole.Text.Substring(inputStart, richTextBoxConsole.SelectionStart - inputStart);
WriteInput(input, Color.White);
}
}