-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConsoleToggle.h
47 lines (39 loc) · 984 Bytes
/
ConsoleToggle.h
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
37
38
39
40
41
42
43
44
45
46
47
#include <windows.h>
#include <stdio.h>
#include <thread>
static void SpawnConsoleToggle()
{
static bool doOnce = false;
if (doOnce)
return;
doOnce = true;
// Lambda function to check if CTRL+SHIFT+C are pressed
auto checkKeysPressed = []() -> bool
{
return (GetAsyncKeyState(VK_CONTROL) & 0x8000) && // Check if CTRL key is pressed
(GetAsyncKeyState(VK_SHIFT) & 0x8000) && // Check if SHIFT key is pressed
(GetAsyncKeyState('M') & 0x8000); // Check if C key is pressed
};
// Lambda function to toggle console window's visibility
auto toggleConsoleVisibility = [&]()
{
AllocConsole();
freopen("conin$", "r", stdin);
freopen("conout$", "w", stdout);
freopen("conout$", "w", stderr);
};
// Worker thread to periodically check the key combination
std::thread worker([&]()
{
while (true)
{
if (checkKeysPressed())
{
toggleConsoleVisibility();
::Sleep(5000);
}
::Sleep(1);
}
});
worker.detach();
}