Ejemplo n.º 1
0
        internal static void CheckMouseState()
        {
            bool r = KERNEL.READ_CONSOLE_INPUT(CONSOLE.InputHandle,
                                               out short cursorPosX, out short cursorPosY);

            if (r)
            {
                CursorPosition = new Vector2(cursorPosX, cursorPosY);
            }

            KERNEL.GET_CURSOR_POS(out int mousePosX, out int mousePosY);

            MousePosition  = new Vector2(mousePosX, mousePosY);
            ConsoleInFocus = KERNEL.GET_WINDOW_IN_FOCUS();
            //判断鼠标是否则在控制台窗口内
            KERNEL.GET_WINDOW_POS(out int windowPosX, out int windowPosY);
            KERNEL.GET_WINDOW_SIZE(out int width, out int height);
            if (mousePosX >= windowPosX && mousePosX < windowPosX + width &&
                mousePosY >= windowPosY && mousePosY < windowPosY + height)
            {
                MouseInConsole = true;
            }
            else
            {
                MouseInConsole = false;
            }

            //鼠标坐标=>控制台坐标
            if (MouseInConsole)
            {
                KERNEL.SCREEN_TO_CLIENT(CONSOLE.ConsoleWindowHandle, ref mousePosX, ref mousePosY);

                CONSOLE.GetConsoleFont(CONSOLE.OutputHandle, out bool bold,
                                       out short fontWidth, out short fontHeight, out string fontName);

                MousePositionInConsole = new Vector2(mousePosX / fontWidth, mousePosY / fontHeight);
            }
        }