| 1 |
/* |
| 2 |
* Sending VK_PAUSE to the console window almost works as a mechanism for |
| 3 |
* pausing it, but it doesn't because the console could turn off the |
| 4 |
* ENABLE_LINE_INPUT console mode flag. |
| 5 |
*/ |
| 6 |
|
| 7 |
#define _WIN32_WINNT 0x0501 |
| 8 |
#include <stdio.h> |
| 9 |
#include <stdlib.h> |
| 10 |
#include <windows.h> |
| 11 |
|
| 12 |
CALLBACK DWORD pausingThread(LPVOID dummy) |
| 13 |
{ |
| 14 |
if (1) { |
| 15 |
Sleep(1000); |
| 16 |
HWND hwnd = GetConsoleWindow(); |
| 17 |
SendMessage(hwnd, WM_KEYDOWN, VK_PAUSE, 1); |
| 18 |
Sleep(1000); |
| 19 |
SendMessage(hwnd, WM_KEYDOWN, VK_ESCAPE, 1); |
| 20 |
} |
| 21 |
|
| 22 |
if (0) { |
| 23 |
INPUT_RECORD ir; |
| 24 |
memset(&ir, 0, sizeof(ir)); |
| 25 |
ir.EventType = KEY_EVENT; |
| 26 |
ir.Event.KeyEvent.bKeyDown = TRUE; |
| 27 |
ir.Event.KeyEvent.wVirtualKeyCode = VK_PAUSE; |
| 28 |
ir.Event.KeyEvent.wRepeatCount = 1; |
| 29 |
} |
| 30 |
|
| 31 |
return 0; |
| 32 |
} |
| 33 |
|
| 34 |
int main() |
| 35 |
{ |
| 36 |
HANDLE hin = GetStdHandle(STD_INPUT_HANDLE); |
| 37 |
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); |
| 38 |
COORD c = { 0, 0 }; |
| 39 |
|
| 40 |
DWORD mode; |
| 41 |
GetConsoleMode(hin, &mode); |
| 42 |
SetConsoleMode(hin, mode & |
| 43 |
~(ENABLE_LINE_INPUT)); |
| 44 |
|
| 45 |
CreateThread(NULL, 0, |
| 46 |
pausingThread, NULL, |
| 47 |
0, NULL); |
| 48 |
|
| 49 |
int i = 0; |
| 50 |
while (true) { |
| 51 |
Sleep(100); |
| 52 |
printf("%d\n", ++i); |
| 53 |
} |
| 54 |
|
| 55 |
return 0; |
| 56 |
} |