Last active
October 29, 2020 13:11
-
-
Save newyear2006/388f23ab3988a6c77fd8292541b339cd to your computer and use it in GitHub Desktop.
Um den Konsolen Cursor in Windows mittels Powershell ein- und ausschalten zu können
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$MethodDefinitions = @' | |
using System; | |
using System.Runtime.InteropServices; | |
public class ConsoleCursor { | |
[StructLayout(LayoutKind.Sequential)] | |
internal struct CONSOLE_CURSOR_INFO | |
{ | |
internal uint Size; | |
internal bool Visible; | |
} | |
[DllImport("kernel32.dll", SetLastError = true)] | |
internal static extern IntPtr GetStdHandle(int nStdHandle); | |
[DllImport("kernel32.dll", SetLastError = true)] | |
internal static extern bool GetConsoleCursorInfo(IntPtr hConsoleOutput, | |
out CONSOLE_CURSOR_INFO lpConsoleCursorInfo); | |
[DllImport("kernel32.dll", SetLastError = true)] | |
internal static extern bool SetConsoleCursorInfo(IntPtr hConsoleOutput, | |
[In] ref CONSOLE_CURSOR_INFO lpConsoleCursorInfo); | |
internal static void SetCursor(bool OnOff) | |
{ | |
var cci = new CONSOLE_CURSOR_INFO(); | |
var handle = GetStdHandle(-11); // -11 = STD_OUTPUT_HANDLE | |
GetConsoleCursorInfo(handle, out cci); | |
cci.Visible = OnOff; | |
SetConsoleCursorInfo(handle, ref cci); | |
} | |
public static void On() | |
{ | |
SetCursor(true); | |
} | |
public static void Off() | |
{ | |
SetCursor(false); | |
} | |
} | |
'@ | |
Add-Type $MethodDefinitions | |
[ConsoleCursor]::Off(); Start-Sleep -Seconds 2; [ConsoleCursor]::On() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment