606 {
607 int numEventsRead = -1;
608 global::Interop.InputRecord
buffer;
610 {
612 {
615 {
616 _cachedInputRecord.eventType = -1;
617 }
618 else
619 {
621 }
622 }
623 else
624 {
625 while (true)
626 {
627 if (!global::Interop.Kernel32.ReadConsoleInput(
InputHandle, out
buffer, 1, out numEventsRead) || numEventsRead == 0)
628 {
630 }
631 short virtualKeyCode =
buffer.keyEvent.virtualKeyCode;
633 {
634 continue;
635 }
638 {
639 break;
640 }
641 if (consoleKey < ConsoleKey.NumPad0 || consoleKey >
ConsoleKey.NumPad9)
642 {
643 switch (consoleKey)
644 {
655 continue;
656 }
657 break;
658 }
659 }
660 if (
buffer.keyEvent.repeatCount > 1)
661 {
662 buffer.keyEvent.repeatCount--;
664 }
665 }
666 }
669 bool alt = (controlKeyState & (ControlKeyState.RightAltPressed |
ControlKeyState.LeftAltPressed)) != 0;
670 bool control = (controlKeyState & (ControlKeyState.RightCtrlPressed |
ControlKeyState.LeftCtrlPressed)) != 0;
671 ConsoleKeyInfo result =
new ConsoleKeyInfo(
buffer.keyEvent.uChar, (
ConsoleKey)
buffer.keyEvent.virtualKeyCode, shift, alt, control);
672 if (!intercept)
673 {
674 Console.Write(
buffer.keyEvent.uChar);
675 }
676 return result;
677 }
static bool IsModKey(global::Interop.InputRecord ir)
static IntPtr InputHandle
static bool IsAltKeyDown(global::Interop.InputRecord ir)
static readonly object s_readKeySyncObject
static bool IsKeyDownEvent(global::Interop.InputRecord ir)
static global::Interop.InputRecord _cachedInputRecord
static string InvalidOperation_ConsoleReadKeyOnFile
@ InvalidOperationException