private bool getCursorVisibility() { CONSOLE_CURSOR_INFO cci = new CONSOLE_CURSOR_INFO(); bool result = APICall.GetConsoleCursorInfo(_hConsoleOut, out cci); return(cci.bVisible); }
public bool SetCursorVisibility(int Size, bool Visible) { CONSOLE_CURSOR_INFO cci = new CONSOLE_CURSOR_INFO { dwSize = (uint)Size, bVisible = Visible }; return(APICall.SetConsoleCursorInfo(_hConsoleOut, ref cci)); }
/// <summary> /// Sets the console cursor position relative to the buffer frame. /// </summary> /// <param name="X">X position</param> /// <param name="Y">Y position</param> public void SetCursorPosition(int X, int Y) { _cursorPosition = new Coord((short)(X + this.X), (short)(Y + this.Y)); if (!APICall.SetConsoleCursorPosition(_hConsoleOut, _cursorPosition)) { Write(0, 0, "Failed to update cursor position.", ConsoleColor.Red); WriteBuffer(); } }
/// <summary> /// Reads the first character from the input. /// </summary> /// <returns>Returns the first character of the string inputed.</returns> public string Read() { StringBuilder sb = new StringBuilder(); uint read = 0; if (APICall.ReadConsole(_hConsoleIn, sb, 1, out read, IntPtr.Zero)) { return(sb.ToString(0, (int)read)); } return(string.Empty); }
/// <summary> /// Reads input until ended. /// </summary> /// <returns>Returns input as a string.</returns> public string ReadLine() { const int maxCount = 256; StringBuilder sb = new StringBuilder(maxCount); uint read = 0; if (APICall.ReadConsole(_hConsoleIn, sb, maxCount, out read, IntPtr.Zero)) { return(sb.ToString(0, (int)read - 1)); } return(string.Empty); }
/// <summary> /// Draws the frame to the console window. This is only needed if you aren't using Run() to /// automatically call the WriteBuffer() method. /// </summary> public void WriteBuffer() { // Copies the child frames to the parent frame for "rendering" //RenderChildren(); // if the handle is valid, then go ahead and write to the console if (_hConsoleOut != null && !_hConsoleOut.IsInvalid) { bool b = APICall.WriteConsoleOutput(_hConsoleOut, _buffer, new Coord() { X = _bufferwidth, Y = _bufferheight }, new Coord() { X = 0, Y = 0 }, ref _rect); } }
// TODO 5: create a check to insure the handles are good to go public ConsoleFrame(int X, int Y, int Width, int Height) { // grabs the handle for the console window _hConsoleOut = APICall.CreateFile("CONOUT$", 0x40000000 | 0x80000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero); _hConsoleIn = APICall.CreateFile("CONIN$", 0x80000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero); this.X = X; this.Y = Y; this.Width = Width; this.Height = Height; _buffer = new CharInfo[this.Width * this.Height]; _rect = new SMALL_RECT() { Left = (short)this.X, Top = (short)this.Y, Right = (short)(this.Width + this.X), Bottom = (short)(this.Height + this.Y) }; }
/// <summary> /// Returns read key as a Virtual Key /// </summary> /// <returns>Virtual Key</returns> public VirtualKeys ReadAsVirtualKey() { int a = APICall._getch(); if (a == 0 || a == 0xE0) { int b = APICall._getch(); b = (int)APICall.MapVirtualKey((uint)b, 1); return((VirtualKeys)b); } StringBuilder sb = new StringBuilder(); APICall.GetKeyboardLayoutName(sb); IntPtr ptr = APICall.LoadKeyboardLayout(sb.ToString(), 1); char c = (char)APICall.VkKeyScanEx((char)a, ptr); APICall.UnloadKeyboardLayout(ptr); return((VirtualKeys)c); }
/// <summary> /// Returns a char based on the key pressed provided /// </summary> /// <returns>Char</returns> public char ReadKey() { return((char)APICall._getch()); }
/// <summary> /// Sets the title of the console window. /// </summary> public void SetConsoleTitle(string Title) { APICall.SetConsoleTitle(Title); }
protected void getInput() { uint read = 0; uint readEvents = 0; if (APICall.GetNumberOfConsoleInputEvents(_hConsoleIn, out read) && read > 0) { INPUT_RECORD[] eventBuffer = new INPUT_RECORD[read]; APICall.ReadConsoleInput(_hConsoleIn, eventBuffer, read, out readEvents); for (int i = 0; i < readEvents; i++) { ControlKeyState conState = eventBuffer[i].KeyEvent.dwControlKeyState; conState &= ~( ControlKeyState.NumLockOn | ControlKeyState.ScrollLockOn | ControlKeyState.CapsLockOn); switch (eventBuffer[i].EventType) { case EventType.KEY_EVENT: if (eventBuffer[i].KeyEvent.bKeyDown) { Key_Pressed?.Invoke(eventBuffer[i].KeyEvent.wVirtualKeyCode, conState); } else { Key_Released?.Invoke(eventBuffer[i].KeyEvent.wVirtualKeyCode, conState); } break; case EventType.MOUSE_EVENT: if (eventBuffer[i].MouseEvent.dwEventFlags == MouseEventType.MOUSE_MOVED) { Mouse_Moved?.Invoke( eventBuffer[i].MouseEvent.dwMousePosition.X, eventBuffer[i].MouseEvent.dwMousePosition.Y); } if (eventBuffer[i].MouseEvent.dwEventFlags == MouseEventType.MOUSE_WHEELED) { MouseWheeled dir; if (eventBuffer[i].MouseEvent.dwButtonState > 0) { dir = MouseWheeled.Up; } else { dir = MouseWheeled.Down; } Mouse_Wheeled?.Invoke( dir); } if (eventBuffer[i].MouseEvent.dwButtonState > 0) { if (eventBuffer[i].MouseEvent.dwEventFlags == MouseEventType.DOUBLE_CLICK) { MouseButton_DoubleClicked?.Invoke( eventBuffer[i].MouseEvent.dwMousePosition.X, eventBuffer[i].MouseEvent.dwMousePosition.Y, eventBuffer[i].MouseEvent.dwButtonState); } else { MouseButton_Clicked?.Invoke( eventBuffer[i].MouseEvent.dwMousePosition.X, eventBuffer[i].MouseEvent.dwMousePosition.Y, eventBuffer[i].MouseEvent.dwButtonState); } } break; } } } }