Esempio n. 1
0
        public static ConsoleKeyInfo ReadKey()
        {
            NativeConsole.INPUT_RECORD[] keyInfo = new NativeConsole.INPUT_RECORD[1];
            //var test = Console.ReadKey();

            uint nRead;

            while (NativeConsole.ReadConsoleInput(NativeConsole.GetStdHandle(NativeConsole.STD_INPUT_HANDLE), keyInfo, 1, out nRead) && nRead != 0)
            {
                //Debug.WriteLine("{0} {1} {2}", keyInfo[0].EventType, keyInfo[0].KeyEvent.bKeyDown, (int)keyInfo[0].KeyEvent.UnicodeChar);

                if (keyInfo[0].EventType == NativeConsole.InputEventType.Key &&
                    keyInfo[0].KeyEvent.bKeyDown &&
                    keyInfo[0].KeyEvent.UnicodeChar != 0)
                {
                    var test1 = new ConsoleKeyInfo(keyInfo[0].KeyEvent.UnicodeChar,
                                                   (ConsoleKey)keyInfo[0].KeyEvent.wVirtualKeyCode,
                                                   (keyInfo[0].KeyEvent.dwControlKeyState & NativeConsole.ControlKeyStates.ShiftPressed) != 0,
                                                   (keyInfo[0].KeyEvent.dwControlKeyState & (NativeConsole.ControlKeyStates.LeftAltPressed | NativeConsole.ControlKeyStates.RightAltPressed)) != 0,
                                                   (keyInfo[0].KeyEvent.dwControlKeyState & (NativeConsole.ControlKeyStates.LeftCtrlPressed | NativeConsole.ControlKeyStates.RightAltPressed)) != 0
                                                   );
                    return(test1);
                }
            }

            throw new NotImplementedException();
        }
Esempio n. 2
0
        static Console2()
        {
            defaultHandle = NativeConsole.GetStdHandle(NativeConsole.STD_OUTPUT_HANDLE);
            currentHandle = defaultHandle;


            NativeConsole.CONSOLE_SCREEN_BUFFER_INFO info;
            NativeConsole.GetConsoleScreenBufferInfo(currentHandle, out info);


            foregroundColor = (ConsoleColor)(info.wAttributes & 0x0F);
            backgroundColor = (ConsoleColor)((info.wAttributes & 0xF0) >> 4);

            bufferSize = new NativeConsole.COORD(80, 35);
        }