Exemplo n.º 1
0
        public void Buffer_CursorTop_Test()
        {
            var process = new Process {
                StartInfo = { FileName = "cmd.exe" }
            };

            process.Start();

            AttachConsole(process.Id);
            var buffer = JConsole.GetActiveScreenBuffer();

            Assert.That(buffer.CursorTop, Is.EqualTo(3));
            Assert.That(buffer.CursorLeft, Is.GreaterThan(0));



            var events = new List <EventArgs>();

            events.Add(new ConsoleKeyEventArgs {
                KeyDown = true, RepeatCount = 1, KeyChar = 'd'
            });
            events.Add(new ConsoleKeyEventArgs {
                KeyDown = false, RepeatCount = 1, KeyChar = 'd'
            });
            events.Add(new ConsoleKeyEventArgs {
                KeyDown = true, RepeatCount = 1, KeyChar = 'i'
            });
            events.Add(new ConsoleKeyEventArgs {
                KeyDown = false, RepeatCount = 1, KeyChar = 'i'
            });
            events.Add(new ConsoleKeyEventArgs {
                KeyDown = true, RepeatCount = 1, KeyChar = 'r'
            });
            events.Add(new ConsoleKeyEventArgs {
                KeyDown = false, RepeatCount = 1, KeyChar = 'r'
            });
            events.Add(new ConsoleKeyEventArgs {
                KeyDown = true, RepeatCount = 1, KeyChar = (char)13
            });
            events.Add(new ConsoleKeyEventArgs {
                KeyDown = false, RepeatCount = 1, KeyChar = (char)13
            });

            var inputBuffer = JConsole.GetInputBuffer();

            inputBuffer.WindowInput = true;
            inputBuffer.WriteEvents(events, events.Count());

            buffer.WriteLine(buffer.OutputMode.ToString());
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            using (ConsoleInputBuffer ib = JConsole.GetInputBuffer())
            {
                while (true)
                {
                    ConsoleInputEventInfo[] events = ib.ReadEvents(10);
                    Console.WriteLine("{0} events", events.Length);
                    foreach (ConsoleInputEventInfo ev in events)
                    {
                        Console.WriteLine("Event type = {0}", ev.EventType);
                        switch (ev.EventType)
                        {
                        case ConsoleInputEventType.KeyEvent:
                            Console.WriteLine("Key {0}", ev.KeyEvent.KeyDown ? "down" : "up");
                            Console.WriteLine("Scan code = {0}", ev.KeyEvent.VirtualScanCode);
                            Console.WriteLine("Virtual key code = {0}", ev.KeyEvent.VirtualKeyCode);
                            Console.WriteLine("Control key state = {0}", ev.KeyEvent.ControlKeyState);
                            Console.WriteLine("Ascii char = {0}", ev.KeyEvent.AsciiChar);
                            break;

                        case ConsoleInputEventType.MouseEvent:
                            if ((ev.MouseEvent.EventFlags & (ConsoleMouseEventType)0xfffff) == 0)
                            {
                                Console.Write("Mouse button,");
                            }
                            if ((ev.MouseEvent.EventFlags & ConsoleMouseEventType.DoubleClick) != 0)
                            {
                                Console.Write("Double click,");
                            }
                            if ((ev.MouseEvent.EventFlags & ConsoleMouseEventType.MouseWheeled) != 0)
                            {
                                Console.Write("Mouse wheeled,");
                            }
                            if ((ev.MouseEvent.EventFlags & ConsoleMouseEventType.MouseMoved) != 0)
                            {
                                Console.Write("Mouse moved,");
                            }
                            if ((ev.MouseEvent.EventFlags & ConsoleMouseEventType.MouseHWheeled) != 0)
                            {
                                Console.Write("Mouse hWheeled,");
                            }
                            Console.WriteLine("Button state = {0}", ev.MouseEvent.ButtonState);
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        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();
            }
        }
Exemplo n.º 4
0
        public void Should_Send_Typed_Content_To_Console()
        {
            var process = new Process {
                StartInfo = { FileName = "cmd.exe" }
            };

            process.Start();

            AttachConsole(process.Id);
            var buffer = JConsole.GetActiveScreenBuffer();

            Assert.That(buffer.CursorTop, Is.EqualTo(3));

            buffer.SetWindowPosition(0, 1);

            var events = new List <EventArgs>();

            events.Add(new ConsoleKeyEventArgs {
                KeyDown = true, RepeatCount = 1, KeyChar = 'd'
            });
            events.Add(new ConsoleKeyEventArgs {
                KeyDown = false, RepeatCount = 1, KeyChar = 'd'
            });
            events.Add(new ConsoleKeyEventArgs {
                KeyDown = true, RepeatCount = 1, KeyChar = 'i'
            });
            events.Add(new ConsoleKeyEventArgs {
                KeyDown = false, RepeatCount = 1, KeyChar = 'i'
            });
            events.Add(new ConsoleKeyEventArgs {
                KeyDown = true, RepeatCount = 1, KeyChar = 'r'
            });
            events.Add(new ConsoleKeyEventArgs {
                KeyDown = false, RepeatCount = 1, KeyChar = 'r'
            });
            events.Add(new ConsoleKeyEventArgs {
                KeyDown = true, RepeatCount = 1, KeyChar = (char)13
            });
            events.Add(new ConsoleKeyEventArgs {
                KeyDown = false, RepeatCount = 1, KeyChar = (char)13
            });

            var inputBuffer = JConsole.GetInputBuffer();

            inputBuffer.WindowInput = true;
            inputBuffer.WriteEvents(events, events.Count());
        }
Exemplo n.º 5
0
        private void WriteEventsToConsoleProcess(char key)
        {
            var events = new List <EventArgs>
            {
                new ConsoleKeyEventArgs {
                    KeyChar = key, KeyDown = true, RepeatCount = 1
                },
                new ConsoleKeyEventArgs {
                    KeyChar = key, KeyDown = false, RepeatCount = 1
                }
            };

            var inputBuffer = JConsole.GetInputBuffer();

            inputBuffer.WindowInput = true;
            inputBuffer.WriteEvents(events.ToArray(), events.Count);
        }
Exemplo n.º 6
0
        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();
            }
        }