-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathConsoleMode.cs
36 lines (30 loc) · 884 Bytes
/
ConsoleMode.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Runtime.InteropServices;
namespace nsZip
{
public static class ConsoleMode
{
[DllImport("kernel32.dll", SetLastError = true)]
private static extern IntPtr GetStdHandle(int nStdHandle);
[DllImport("kernel32.dll")]
private static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode);
[DllImport("kernel32.dll")]
private static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode);
public static bool TryDisablingConsoleQuickEdit()
{
//Standard input device
const int STD_INPUT_HANDLE = -10;
const uint ENABLE_QUICK_EDIT = 0x40;
var consoleHandle = GetStdHandle(STD_INPUT_HANDLE);
if (GetConsoleMode(consoleHandle, out var consoleMode))
{
consoleMode &= ~ENABLE_QUICK_EDIT;
if (SetConsoleMode(consoleHandle, consoleMode))
{
return true;
}
}
return false;
}
}
}