示例#1
0
 private static void RestoreConsoleState()
 {
     NativeWin.SetConsoleMode(consoleHandle, initialConsoleMode);
     Console.WindowWidth  = initialWindowWidth;
     Console.WindowHeight = initialWindowHeight;
     Console.BufferWidth  = initialBufferWidth;
     Console.BufferHeight = initialBufferHeight;
     Console.Clear();
     NativeWin.SetConsoleResizeEnabled(true);
 }
示例#2
0
        private static void PollEvents()
        {
            int read  = 0;
            int count = 0;


            NativeWin.GetNumberOfConsoleInputEvents(consoleHandle, ref count);
            while (count > 0)
            {
                NativeWin.ReadConsoleInput(consoleHandle, records, 100, ref read);
                for (int i = 0; i < read; i++)
                {
                    NativeWin.INPUT_RECORD e = records[i];
                    if (e.eventType == NativeWin.ConsoleEventType.WINDOW_BUFFER_SIZE_EVENT)
                    {
                        ResizeFitConsole();
                    }
                    else if (e.eventType == NativeWin.ConsoleEventType.KEY_EVENT)
                    {
                    }
                    else if (e.eventType == NativeWin.ConsoleEventType.MOUSE_EVENT)
                    {
                        if ((prevButtonState & 1) == 0 && (e.mouseEvent.dwButtonState & 1) == 1)
                        {
                            window.MouseEvent(new MouseArgs()
                            {
                                X      = e.mouseEvent.dwMousePosition.X,
                                Y      = e.mouseEvent.dwMousePosition.Y,
                                button = MouseButton.Left,
                                type   = MouseEventType.Press,
                                inside = true
                            });
                        }
                        if ((prevButtonState & 1) == 1 && (e.mouseEvent.dwButtonState & 1) == 0)
                        {
                            window.MouseEvent(new MouseArgs()
                            {
                                X      = e.mouseEvent.dwMousePosition.X,
                                Y      = e.mouseEvent.dwMousePosition.Y,
                                button = MouseButton.Left,
                                type   = MouseEventType.Release,
                                inside = true
                            });
                        }
                        prevButtonState = e.mouseEvent.dwButtonState;
                    }
                }
                NativeWin.GetNumberOfConsoleInputEvents(consoleHandle, ref count);
            }
        }
示例#3
0
        private static void SetupConsole()
        {
            initialBufferWidth  = Console.BufferWidth;
            initialBufferHeight = Console.BufferHeight;
            initialWindowWidth  = Console.WindowWidth;
            initialWindowHeight = Console.WindowHeight;
            SetConsoleSize();

            consoleHandle = FastConsole.Native.GetStdHandle(FastConsole.Native.nStdHandle.STD_INPUT_HANDLE);
            NativeWin.GetConsoleMode((IntPtr)consoleHandle, ref initialConsoleMode);

            NativeWin.SetConsoleMode(consoleHandle,
                                     (uint)(NativeWin.ConsoleInputMode.ENABLE_MOUSE_INPUT | NativeWin.ConsoleInputMode.ENABLE_EXTENDED_FLAGS | NativeWin.ConsoleInputMode.ENABLE_WINDOW_INPUT));

            ResizeFitConsole();

            if (!resizable)
            {
                NativeWin.SetConsoleResizeEnabled(false);
            }
        }