-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
61 lines (58 loc) · 1.56 KB
/
test.cpp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <windows.h>
#include <stdio.h>
int main(void)
{
HANDLE hStdInput,hStdOutput;
INPUT_RECORD ir[128];
bool blnLoop=true;
DWORD nRead;
COORD xy;
UINT i;
hStdInput=GetStdHandle(STD_INPUT_HANDLE);
hStdOutput=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleMode(hStdInput,ENABLE_MOUSE_INPUT|ENABLE_EXTENDED_FLAGS); //<<<flags
FlushConsoleInputBuffer(hStdInput);
do
{
if(WaitForSingleObject(hStdInput,1000)==WAIT_TIMEOUT)
break;
else
{
ReadConsoleInput(hStdInput,ir,128,&nRead);
for(i=0;i<nRead;i++)
{
switch(ir[i].EventType)
{
case KEY_EVENT:
if(ir[i].Event.KeyEvent.wVirtualKeyCode==VK_ESCAPE)
blnLoop=false;
else
{
xy.X=0;xy.Y=0;
SetConsoleCursorPosition(hStdOutput,xy);
printf
(
"AsciiCode = %d: symbol = %c\n",
ir[i].Event.KeyEvent.uChar.AsciiChar,
ir[i].Event.KeyEvent.uChar.AsciiChar
);
}
break;
case MOUSE_EVENT:
xy.X=0, xy.Y=1;
SetConsoleCursorPosition(hStdOutput,xy);
printf
(
"%.3d\t%.3d\t%.3u",
ir[i].Event.MouseEvent.dwMousePosition.X,
ir[i].Event.MouseEvent.dwMousePosition.Y,
(unsigned int)ir[i].Event.MouseEvent.dwButtonState & 0x07
);
break;
}//end switch
}//end for
}//end if
}//end do
while(blnLoop==true);
return 0;
}