internal TerminalSink() { this.outputHandle = TerminalInstance.CreateFileW( "CONOUT$", 0x40000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero); if (this.outputHandle.IsInvalid) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } this.outputStreamHandle = TerminalInstance.GetStdHandle(STD_OUTPUT_HANDLE); if (this.outputStreamHandle.IsInvalid) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } }
internal TerminalSource() { this.inputHandle = TerminalInstance.CreateFileW( "CONIN$", 0x80000000, 1, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero); if (this.inputHandle.IsInvalid) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } this.inputStreamHandle = TerminalInstance.GetStdHandle(STD_INPUT_HANDLE); if (this.inputStreamHandle.IsInvalid) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } lastMouseEvent = default; this.mouse = new Mouse(); this.onExitRequested = new Observable <ExitRequestedEventArgs>(); this.onExitAccepted = new Observable <ExitAcceptedEventArgs>(); this.onKeyPressed = new Observable <TerminalKeyInfo>(); this.onKeyReleased = new Observable <TerminalKeyInfo>(); this.onKeyPressedInternal = new Observable <TerminalKeyInfo>(); this.onKeyReleasedInternal = new Observable <TerminalKeyInfo>(); this.onKeyPressedInternal.Subscribe( new Observer <TerminalKeyInfo>( x => { if (!this.keyboardSuppressed) { this.onKeyPressed.Next(x); } }, x => this.onKeyPressed.Error(x), () => this.onKeyPressed.Complete())); this.onKeyReleasedInternal.Subscribe( new Observer <TerminalKeyInfo>( x => { if (!this.keyboardSuppressed) { this.onKeyReleased.Next(x); } }, x => this.onKeyReleased.Error(x), () => this.onKeyReleased.Complete())); this.consoleControlHandler = (consoleControlEventType) => { if (consoleControlEventType == ConsoleControlEventType.CtrlC || consoleControlEventType == ConsoleControlEventType.CtrlBreak || consoleControlEventType == ConsoleControlEventType.CtrlClose) { return(this.RequestExit()); } else { return(false); } }; SetConsoleCtrlHandler( this.consoleControlHandler, true); this.mouseEnabled = false; this.keyboardEnabled = false; this.keyboardSuppressed = false; this.eventThreadRunning = new Box <bool>(true); this.eventThread = new Thread( () => { bool GetRunningState() { lock (this.eventThreadRunning) { return(this.eventThreadRunning.Value); } } while (GetRunningState()) { while (this.ListenForEvents(out ConsoleInputEventInfo[] events)) { foreach (ConsoleInputEventInfo @event in events) { this.DispatchEventProcessing(@event); } } } }); this.eventThread.Start(); }