Support text pasting with Ctrl+V

This commit is contained in:
ORelio 2014-01-11 12:48:59 +01:00
parent d012905b65
commit bca2a4116c
2 changed files with 99 additions and 66 deletions

View file

@ -2,6 +2,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace MinecraftClient namespace MinecraftClient
{ {
@ -80,6 +82,14 @@ namespace MinecraftClient
k = Console.ReadKey(true); k = Console.ReadKey(true);
while (writing_lock) { } while (writing_lock) { }
reading_lock = true; reading_lock = true;
if (k.Key == ConsoleKey.V && k.Modifiers == ConsoleModifiers.Control)
{
string clip = ReadClipboard();
foreach (char c in clip)
AddChar(c);
}
else
{
switch (k.Key) switch (k.Key)
{ {
case ConsoleKey.Escape: case ConsoleKey.Escape:
@ -152,6 +162,7 @@ namespace MinecraftClient
AddChar(k.KeyChar); AddChar(k.KeyChar);
break; break;
} }
}
reading_lock = false; reading_lock = false;
} }
while (writing_lock) { } while (writing_lock) { }
@ -212,7 +223,7 @@ namespace MinecraftClient
} }
#endregion #endregion
#region subfunctions #region Subfunctions
private static void ClearLineAndBuffer() private static void ClearLineAndBuffer()
{ {
while (buffer2.Length > 0) { GoRight(); } while (buffer2.Length > 0) { GoRight(); }
@ -275,6 +286,27 @@ namespace MinecraftClient
for (int i = 0; i < buffer2.Length; i++) { GoBack(); } for (int i = 0; i < buffer2.Length; i++) { GoBack(); }
} }
#endregion #endregion
#region Clipboard management
private static string ReadClipboard()
{
string clipdata = "";
Thread staThread = new Thread(new ThreadStart(
delegate
{
try
{
clipdata = Clipboard.GetText();
}
catch { }
}
));
staThread.SetApartmentState(ApartmentState.STA);
staThread.Start();
staThread.Join();
return clipdata;
}
#endregion
} }
/// <summary> /// <summary>

View file

@ -74,6 +74,7 @@
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />