static void ThreadProc(Object stateInfo) { // Simulate a long process. while (true) { System.Threading.Thread.Sleep(1000); sb.WriteLine("tick"); } }
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(); } }
static void Main(string[] args) { using (ConsoleScreenBuffer sb1 = JConsole.GetActiveScreenBuffer()) { sb1.WindowWidth = 50; sb1.Width = sb1.WindowWidth; sb1.WriteLine("Window mode"); sb1.WriteLine(String.Format("Size = {0},{1}", sb1.Width, sb1.Height)); sb1.WriteLine(String.Format("Window = {0},{1}", sb1.WindowWidth, sb1.WindowHeight)); Console.ReadKey(); sb1.SetDisplayMode(ConsoleDisplayMode.Fullscreen); sb1.WriteLine("Full screen mode!"); sb1.WriteLine(String.Format("Size = {0},{1}", sb1.Width, sb1.Height)); sb1.WriteLine(String.Format("Window = {0},{1}", sb1.WindowWidth, sb1.WindowHeight)); Console.ReadKey(); } }
static void Main(string[] args) { // get the active screen buffer and write to it. using (ConsoleScreenBuffer sb1 = JConsole.GetActiveScreenBuffer()) { // Write some stuff... sb1.WriteLine("Default location is (0, 0), with gray on black as the colors."); sb1.ForegroundColor = ConsoleColor.Blue; sb1.BackgroundColor = ConsoleColor.Yellow; sb1.WriteLine("Next line is blue on yellow."); // position the cursor sb1.SetCursorPosition(40, 2); sb1.Write("Press any key..."); // Use Console.ReadKey because we don't have ConsoleInputBuffer yet. Console.ReadKey(); // Clear the screen and reset the colors sb1.Clear(); sb1.WriteLine("Colors remain blue on yellow"); sb1.ResetColor(); sb1.WriteLine("Until we reset the colors"); // and do a positional write string msg = "Press any key..."; sb1.WriteXY(msg, 40, 2); sb1.FillAttributeXY(ConsoleColor.White, ConsoleColor.Red, msg.Length, 40, 2); // must set cursor position because WriteXY doesn't change it sb1.SetCursorPosition(40 + msg.Length, 2); Console.ReadKey(); // Create a new screen buffer using (ConsoleScreenBuffer sb2 = new ConsoleScreenBuffer()) { sb2.WriteLine("Secondary screen buffer!"); sb2.Write("Press any key to return."); JConsole.SetActiveScreenBuffer(sb2); Console.ReadKey(); JConsole.SetActiveScreenBuffer(sb1); } sb1.WriteLine(""); sb1.WriteLine("Back to original screen buffer."); sb1.Write("Press any key to exit"); Console.ReadKey(); // Draw a text-mode button for (int y = 20; y < 23; y++) { sb1.FillCharXY(' ', 10, 20, y); sb1.FillAttributeXY(ConsoleColor.Black, ConsoleColor.Red, 10, 20, y); } sb1.WriteXY(" OK ", 23, 21); sb1.FillAttributeXY(ConsoleColor.Yellow, ConsoleColor.Black, 4, 23, 21); // Define a button ConsoleCharInfo[,] okButton = { { new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)), new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)), new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)), new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)), new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)), new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)), new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)), new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)), new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)), new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)) }, { new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)), new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)), new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)), new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Yellow, ConsoleColor.Black)), new ConsoleCharInfo('O', new ConsoleCharAttribute(ConsoleColor.Yellow, ConsoleColor.Black)), new ConsoleCharInfo('K', new ConsoleCharAttribute(ConsoleColor.Yellow, ConsoleColor.Black)), new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Yellow, ConsoleColor.Black)), new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)), new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)), new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)) }, { new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)), new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)), new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)), new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)), new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)), new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)), new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)), new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)), new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)), new ConsoleCharInfo(' ', new ConsoleCharAttribute(ConsoleColor.Black, ConsoleColor.Red)) } }; // write the button to the screen buffer sb1.WriteBlock(okButton, 0, 0, 60, 20, 70, 22); Console.ReadKey(); } }
static void Main(string[] args) { Random colors = new Random(); using (ConsoleScreenBuffer sb1 = JConsole.GetActiveScreenBuffer()) { // Fill the screen buffer for (int row = 0; row < sb1.Height; row++) { StringBuilder builder = new StringBuilder(sb1.Width); string text = string.Format("Row {0} ", row); while (builder.Length < sb1.Width) { builder.Append(text); } sb1.WriteXY(builder.ToString(), 0, row); ConsoleColor fg = (ConsoleColor)colors.Next(15); ConsoleColor bg = (ConsoleColor)colors.Next(15); sb1.FillAttributeXY(fg, bg, builder.Length, 0, row); } // wait for a key press Console.ReadKey(); // Move a part of the buffer to the top sb1.MoveBufferArea(50, 200, 30, 50, 0, 0); Console.ReadKey(); // Position the window to show the area that was moved sb1.SetWindowPosition(20, 190); Console.ReadKey(); // Create a new screen buffer using (ConsoleScreenBuffer sb2 = new ConsoleScreenBuffer()) { sb2.WriteLine("Second screen buffer"); // Change buffer size and window size sb2.SetBufferSize(100, 100); sb2.SetWindowSize(sb2.MaximumWindowWidth, sb2.MaximumWindowHeight); // set new buffer as active -- changes console window size JConsole.SetActiveScreenBuffer(sb2); Console.ReadKey(); // Show reading screen buffer... sb2.WriteXY("Copied with ReadXY, ReadAttributesXY", 0, 1); string chars = sb1.ReadXY(50, 0, 1); sb2.WriteXY(chars, 0, 2); ConsoleCharAttribute[] attrs = sb1.ReadAtrributesXY(50, 0, 1); sb2.WriteAttributesXY(attrs, 50, 0, 2); sb2.WriteXY("Copied with ReadBlock/WriteBlock", 0, 3); ConsoleCharInfo[,] block = new ConsoleCharInfo[10, 20]; sb1.ReadBlock(block, 0, 0, 20, 100, 40, 110); sb2.WriteBlock(block, 0, 0, 0, 4, 20, 14); Console.ReadKey(); // reset active buffer JConsole.SetActiveScreenBuffer(sb1); } Console.ReadKey(); } }
static void ib_KeyUp(object sender, ConsoleKeyEventArgs e) { sb.WriteLine(String.Format("KeyUp: {0}, {1}", e.Key, e.VirtualScanCode)); }
static void ib_MouseScroll(object sender, ConsoleMouseEventArgs e) { bool bScrollDown = (e.ButtonState & ConsoleMouseButtonState.ScrollDown) != 0; sb.WriteLine(string.Format("Mouse scroll: {0}, {1}", e.EventFlags, bScrollDown ? "down" : "up")); }