Exemple #1
0
        public static void Main2(string[] args)
        {
            string backupTitle = Console.Title;

            Console.WindowHeight = 25;
            Console.BufferHeight = 9000;
            Console.WindowWidth  = 80;
            Console.BufferWidth  = 80;

            Console.WriteLine("VT Tester 2, way better than v1");

            IntPtr hCon = Pinvoke.GetStdHandle(Pinvoke.STD_INPUT_HANDLE);
            int    mode;
            bool   fSuccess = Pinvoke.GetConsoleMode(hCon, out mode);

            if (fSuccess)
            {
                mode    &= ~Pinvoke.ENABLE_PROCESSED_INPUT;
                mode    |= Pinvoke.ENABLE_VIRTUAL_TERMINAL_INPUT;
                fSuccess = Pinvoke.SetConsoleMode(hCon, mode);
            }
            if (!fSuccess)
            {
                return;
            }

            while (true)
            {
                ConsoleKeyInfo keyInfo = Console.ReadKey(false);
                switch (keyInfo.KeyChar)
                {
                case '=':
                case '>':
                    enableVT();
                    Console.Write((char)0x1b);
                    Console.Write(keyInfo.KeyChar);
                    disableVT();
                    break;

                case 'A':
                case 'B':
                case 'C':
                case 'D':
                case 'E':
                case 'F':
                case 'P':
                case 'S':
                case 'T':
                    enableVT();
                    Console.Write((char)0x1b);
                    Console.Write((char)0x5b);
                    Console.Write(keyInfo.KeyChar);
                    disableVT();
                    break;
                }
            }
        }
Exemple #2
0
        public static void disableVT()
        {
            IntPtr hCon = Pinvoke.GetStdHandle(Pinvoke.STD_OUTPUT_HANDLE);
            int    mode;
            bool   fSuccess = Pinvoke.GetConsoleMode(hCon, out mode);

            if (fSuccess)
            {
                mode    &= ~Pinvoke.ENABLE_VIRTUAL_TERMINAL_PROCESSING;
                fSuccess = Pinvoke.SetConsoleMode(hCon, mode);
            }
        }