public void Dispose() { if (!Disposed) { if (Console != null) { Console.Dispose(); Console = null; } Disposed = true; } GC.SuppressFinalize(this); }
static void Main(string[] args) { Console.Title = "testo"; sb = JConsole.GetActiveScreenBuffer(); try { using (ConsoleInputBuffer ib = JConsole.GetInputBuffer()) { // Enable screen buffer window size events ib.WindowInput = true; // show the current input mode ConsoleInputModeFlags mf = ib.InputMode; sb.WriteLine(string.Format("Input mode = {0}, hex: {1:X}", mf, (int)mf)); sb.WriteLine(string.Format("Window Input = {0}", ib.WindowInput)); // set up the event handlers ib.KeyDown += new ConsoleKeyEventHandler(ib_KeyDown); ib.KeyUp += new ConsoleKeyEventHandler(ib_KeyUp); ib.MouseButton += new ConsoleMouseEventHandler(ib_MouseButton); ib.MouseMove += new ConsoleMouseEventHandler(ib_MouseMove); ib.MouseDoubleClick += new ConsoleMouseEventHandler(ib_MouseDoubleClick); ib.MouseScroll += new ConsoleMouseEventHandler(ib_MouseScroll); ib.BufferSizeChange += new ConsoleBufferSizeEventHandler(ib_BufferSizeChange); ib.Focus += new ConsoleFocusEventHandler(ib_Focus); ib.Menu += new ConsoleMenuEventHandler(ib_Menu); // Change buffer size to test window sizing events. sb.SetBufferSize(100, 300); // Queue the thread System.Threading.ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc)); // process events. Control+C will exit the application. while (true) { ib.ProcessEvents(); // Sleep at least 1 ms. If you don't do this, your program // will consume 100% of the processor time. System.Threading.Thread.Sleep(1); } } } finally { sb.Dispose(); } }
static void Main(string[] args) { sb = JConsole.GetActiveScreenBuffer(); try { sb.WriteLine("Write events..."); EventArgs[] ea = new EventArgs[13]; ea[0] = new ConsoleWindowBufferSizeEventArgs(80, 100); ea[1] = MakeKeyEvent('H', ConsoleKey.H, 35, true); ea[2] = MakeKeyEvent('H', ConsoleKey.H, 35, false); ea[3] = MakeKeyEvent('e', ConsoleKey.E, 18, true); ea[4] = MakeKeyEvent('e', ConsoleKey.E, 18, false); ea[5] = MakeKeyEvent('l', ConsoleKey.L, 38, true); ea[6] = MakeKeyEvent('l', ConsoleKey.L, 38, false); ea[7] = MakeKeyEvent('l', ConsoleKey.L, 38, true); ea[8] = MakeKeyEvent('l', ConsoleKey.L, 38, false); ea[9] = MakeKeyEvent('o', ConsoleKey.O, 24, true); ea[10] = MakeKeyEvent('o', ConsoleKey.O, 24, false); ea[11] = MakeKeyEvent(Convert.ToChar(13), ConsoleKey.Enter, 28, true); ea[12] = MakeKeyEvent(Convert.ToChar(13), ConsoleKey.Enter, 28, false); using (ConsoleInputBuffer ib = JConsole.GetInputBuffer()) { ib.WindowInput = true; ib.BufferSizeChange += new ConsoleBufferSizeEventHandler(ib_BufferSizeChange); ib.KeyDown += new ConsoleKeyEventHandler(ib_KeyDown); ib.KeyUp += new ConsoleKeyEventHandler(ib_KeyUp); ib.WriteEvents(ea); ib.ProcessEvents(); // string s = ib.ReadLine(); // sb.WriteLine(String.Format("You said '{0}'", s)); sb.Write("Press any key to exit..."); ib.ReadKey(); } } finally { sb.Dispose(); } }