public ConsoleKeyInfo ReadKey(bool intercept) { int eventsRead; InputRecord record = new InputRecord(); do { if (!ReadConsoleInput(inputHandle, out record, 1, out eventsRead)) { throw new InvalidOperationException("Error in ReadConsoleInput " + Marshal.GetLastWin32Error()); } } while (record.EventType != 1 && !record.KeyDown); // RIGHT_ALT_PRESSED 1 // LEFT_ALT_PRESSED 2 // RIGHT_CTRL_PRESSED 4 // LEFT_CTRL_PRESSED 8 // SHIFT_PRESSED 16 bool alt = ((record.ControlKeyState & 3) != 0); bool ctrl = ((record.ControlKeyState & 12) != 0); bool shift = ((record.ControlKeyState & 16) != 0); return(new ConsoleKeyInfo(record.Character, (ConsoleKey)record.VirtualKeyCode, shift, alt, ctrl)); }
internal static extern bool PeekConsoleInput(IntPtr hConsoleInput, out InputRecord buffer, int numInputRecords_UseOne, out int numEventsRead);
extern static bool ReadConsoleInput(IntPtr handle, out InputRecord record, int length, out int nread);
extern static bool PeekConsoleInput(IntPtr handle, out InputRecord record, int length, out int eventsRead);
extern static bool PeekConsoleInput (IntPtr handle, out InputRecord record, int length, out int eventsRead);
extern static bool ReadConsoleInput (IntPtr handle, out InputRecord record, int length, out int nread);
public ConsoleKeyInfo ReadKey (bool intercept) { int eventsRead; InputRecord record = new InputRecord (); for (;;) { if (!ReadConsoleInput (inputHandle, out record, 1, out eventsRead)) throw new InvalidOperationException ("Error in ReadConsoleInput " + Marshal.GetLastWin32Error ()); if (record.KeyDown && record.EventType == 1 && !IsModifierKey (record.VirtualKeyCode)) break; } // RIGHT_ALT_PRESSED 1 // LEFT_ALT_PRESSED 2 // RIGHT_CTRL_PRESSED 4 // LEFT_CTRL_PRESSED 8 // SHIFT_PRESSED 16 bool alt = ((record.ControlKeyState & 3) != 0); bool ctrl = ((record.ControlKeyState & 12) != 0); bool shift = ((record.ControlKeyState & 16) != 0); return new ConsoleKeyInfo (record.Character, (ConsoleKey) record.VirtualKeyCode, shift, alt, ctrl); }
static bool ReadConsoleInput (IntPtr handle, out InputRecord record, int length, out int nread) { throw new System.NotImplementedException(); }
static bool PeekConsoleInput(IntPtr handle, out InputRecord record, int length, out int eventsRead) { throw new System.NotImplementedException(); }
internal static extern bool WriteConsoleInput( IntPtr hConsoleInput, InputRecord[] lpBuffer, uint nLength, out uint lpNumberOfEventsWritten);
private static extern bool GetConsoleScreenBufferInfo(IntPtr handle, out ConsoleScreenBufferInfo info); // 0x0000000180A78170-0x0000000180A78210 private static extern bool ReadConsoleInput(IntPtr handle, out InputRecord record, int length, out int nread); // 0x0000000180A782D0-0x0000000180A783E0