X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FSystem%2FWindowsConsoleDriver.cs;h=10ba8db45e5afdda5b1afc90d3892f5a6e649e0b;hb=6a5fd42faf8ec8cb0f622aa21522f82cf1df76f9;hp=473f320a0a3c5094725070c4e89eab32fef7bfff;hpb=9948ba470f81ef8b5bcc800cdb334e977afa96af;p=mono.git diff --git a/mcs/class/corlib/System/WindowsConsoleDriver.cs b/mcs/class/corlib/System/WindowsConsoleDriver.cs old mode 100644 new mode 100755 index 473f320a0a3..10ba8db45e5 --- a/mcs/class/corlib/System/WindowsConsoleDriver.cs +++ b/mcs/class/corlib/System/WindowsConsoleDriver.cs @@ -26,7 +26,7 @@ // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // -#if NET_2_0 +#if !MOBILE using System.Runtime.InteropServices; using System.Text; namespace System { @@ -35,6 +35,7 @@ namespace System { public bool Visible; } +#pragma warning disable 169 struct InputRecord { public short EventType; // This is KEY_EVENT_RECORD @@ -48,6 +49,7 @@ namespace System { bool pad2; // } +#pragma warning restore 169 struct CharInfo { public char Character; @@ -98,7 +100,6 @@ namespace System { IntPtr inputHandle; IntPtr outputHandle; short defaultAttribute; - bool inited; public WindowsConsoleDriver () { @@ -236,11 +237,6 @@ namespace System { } } - public bool Echo { // not really used on windows - get { return true; } - set {} - } - public ConsoleColor ForegroundColor { get { ConsoleScreenBufferInfo info = new ConsoleScreenBufferInfo (); @@ -269,7 +265,7 @@ namespace System { return false; //KEY_EVENT == 1 - if (record.EventType == 1 && record.KeyDown) + if (record.EventType == 1 && record.KeyDown && !IsModifierKey (record.VirtualKeyCode)) return true; if (!ReadConsoleInput (inputHandle, out record, 1, out eventsRead)) @@ -334,7 +330,7 @@ namespace System { public bool TreatControlCAsInput { get { int mode; - if (!GetConsoleMode (outputHandle, out mode)) + if (!GetConsoleMode (inputHandle, out mode)) throw new Exception ("Failed in GetConsoleMode: " + Marshal.GetLastWin32Error ()); // ENABLE_PROCESSED_INPUT @@ -343,7 +339,7 @@ namespace System { set { int mode; - if (!GetConsoleMode (outputHandle, out mode)) + if (!GetConsoleMode (inputHandle, out mode)) throw new Exception ("Failed in GetConsoleMode: " + Marshal.GetLastWin32Error ()); bool cAsInput = ((mode & 1) == 0); @@ -353,9 +349,9 @@ namespace System { if (value) mode &= ~1; else - mode++; + mode |= 1; - if (!SetConsoleMode (outputHandle, mode)) + if (!SetConsoleMode (inputHandle, mode)) throw new Exception ("Failed in SetConsoleMode: " + Marshal.GetLastWin32Error ()); } } @@ -438,7 +434,7 @@ namespace System { SmallRect region = new SmallRect (sourceLeft, sourceTop, sourceLeft + sourceWidth - 1, sourceTop + sourceHeight - 1); fixed (void *ptr = &buffer [0]) { if (!ReadConsoleOutput (outputHandle, ptr, bsize, bpos, ref region)) - throw new ArgumentException ("", "Cannot read from the specified coordinates."); + throw new ArgumentException (String.Empty, "Cannot read from the specified coordinates."); } int written; @@ -453,18 +449,38 @@ namespace System { bpos = new Coord (0, 0); region = new SmallRect (targetLeft, targetTop, targetLeft + sourceWidth - 1, targetTop + sourceHeight - 1); if (!WriteConsoleOutput (outputHandle, buffer, bsize, bpos, ref region)) - throw new ArgumentException ("", "Cannot write to the specified coordinates."); + throw new ArgumentException (String.Empty, "Cannot write to the specified coordinates."); + } + + public void Init () + { + } + + public string ReadLine () + { + StringBuilder builder = new StringBuilder (); + bool exit = false; + do { + ConsoleKeyInfo key = ReadKey (false); + char c = key.KeyChar; + exit = (c == '\n'); + if (!exit) + builder.Append (key.KeyChar); + } while (!exit); + return builder.ToString (); } public ConsoleKeyInfo ReadKey (bool intercept) { int eventsRead; InputRecord record = new InputRecord (); - do { + for (;;) { if (!ReadConsoleInput (inputHandle, out record, 1, out eventsRead)) throw new InvalidOperationException ("Error in ReadConsoleInput " + Marshal.GetLastWin32Error ()); - } while (record.EventType != 1 && !record.KeyDown); + if (record.KeyDown && record.EventType == 1 && !IsModifierKey (record.VirtualKeyCode)) + break; + } // RIGHT_ALT_PRESSED 1 // LEFT_ALT_PRESSED 2 @@ -526,6 +542,23 @@ namespace System { throw new ArgumentOutOfRangeException ("left/top", "Windows error " + Marshal.GetLastWin32Error ()); } + static bool IsModifierKey (short virtualKeyCode) + { + // 0x10 through 0x14 is shift/control/alt/pause/capslock + // 0x2C is print screen, 0x90 is numlock, 0x91 is scroll lock + switch (virtualKeyCode) { + case 0x10: + case 0x11: + case 0x12: + case 0x14: + case 0x90: + case 0x91: + return true; + default: + return false; + } + } + // // Imports //