00001
#include <windows.h>
00002
#include <stdio.h>
00003
#include <stdlib.h>
00004
#include <io.h>
00005
00006 PrintUsage() {
00007 printf(
"test case for bug #78891 - reported by Chris Mah, April 15th 1997\n");
00008 printf(
"Uses WriteConsoleInput() to inject keystrokes for \"ESC y\"\n");
00009
00010 printf(
"WritEscY attempts to inject \"ESC y\" into the console input stream\n");
00011 printf(
"It does this by constructing KeyEvents with scancode and VK values for\n");
00012 printf(
"the Escape and Y key obtained via VkKeyScan() and MapVirtualKey().\n");
00013 printf(
"Usage: writescy [-x]\n");
00014 printf(
" -x : use VK_ESCAPE literally\n");
00015 printf(
" (default uses VkKeyScanEx(0x1b) to get the VK)\n");
00016 }
00017
00018 int _cdecl
main(
int argc,
char *argv[]) {
00019
DWORD dwNumWrites;
00020 INPUT_RECORD inputESC_Y[6];
00021
BOOL retval;
00022
int iArg;
00023
BOOL fLiteral =
FALSE;
00024
00025
00026
00027
00028
for (iArg=1; iArg<argc; iArg++) {
00029
if ((argv[iArg][0] ==
'-') || (argv[iArg][0] ==
'/')) {
00030
switch (argv[iArg][1]) {
00031
case 'x':
00032 fLiteral =
TRUE;
00033
break;
00034
00035
default:
00036 printf(
"ERROR: Invalid flag %c\n", argv[iArg][1]);
00037
00038
case '?':
00039
PrintUsage();
00040
return 0;
00041 }
00042 }
else {
00043
PrintUsage();
00044
return 0;
00045 }
00046 }
00047
00048 printf(
"VkKeyScan(0x1b) returns 0x%02x\n",
VkKeyScan(0x1b));
00049 printf(
"MapVirtualKey(VkKeyScan(0x1b),0) returns 0x%02x\n",
MapVirtualKey(
VkKeyScan(0x1b),0));
00050
00051 printf(
"VK_ESCAPE is 0x%02x\n", VK_ESCAPE);
00052 printf(
"MapVirtualKey(VK_ESCAPE,0) returns 0x%02x\n",
MapVirtualKey(VK_ESCAPE,0));
00053 printf(
"========================================================\n\n");
00054
00055
if (!fLiteral) {
00056 printf(
"Using VkKeyScan(0x1b): ");
00057 inputESC_Y[0].EventType = KEY_EVENT;
00058 inputESC_Y[0].Event.KeyEvent.bKeyDown =
TRUE;
00059 inputESC_Y[0].Event.KeyEvent.wRepeatCount = 1;
00060 inputESC_Y[0].Event.KeyEvent.wVirtualKeyCode =
VkKeyScan(27);
00061 inputESC_Y[0].Event.KeyEvent.wVirtualScanCode =
MapVirtualKey(
VkKeyScan(27),0);
00062 inputESC_Y[0].Event.KeyEvent.uChar.AsciiChar = 27;
00063 inputESC_Y[0].Event.KeyEvent.dwControlKeyState = 0;
00064
00065 inputESC_Y[1].EventType = KEY_EVENT;
00066 inputESC_Y[1].Event.KeyEvent.bKeyDown =
FALSE;
00067 inputESC_Y[1].Event.KeyEvent.wRepeatCount = 1;
00068 inputESC_Y[1].Event.KeyEvent.wVirtualKeyCode =
VkKeyScan(27);
00069 inputESC_Y[1].Event.KeyEvent.wVirtualScanCode =
MapVirtualKey(
VkKeyScan(27),0);
00070 inputESC_Y[1].Event.KeyEvent.uChar.AsciiChar = 27;
00071 inputESC_Y[1].Event.KeyEvent.dwControlKeyState = 0;
00072
00073 inputESC_Y[2].EventType = KEY_EVENT;
00074 inputESC_Y[2].Event.KeyEvent.bKeyDown =
TRUE;
00075 inputESC_Y[2].Event.KeyEvent.wRepeatCount = 1;
00076 inputESC_Y[2].Event.KeyEvent.wVirtualKeyCode =
VkKeyScan(
'y');
00077 inputESC_Y[2].Event.KeyEvent.wVirtualScanCode =
MapVirtualKey(
VkKeyScan(
'y'),0);
00078 inputESC_Y[2].Event.KeyEvent.uChar.AsciiChar =
'y';
00079 inputESC_Y[2].Event.KeyEvent.dwControlKeyState = 0;
00080
00081 inputESC_Y[3].EventType = KEY_EVENT;
00082 inputESC_Y[3].Event.KeyEvent.bKeyDown =
FALSE;
00083 inputESC_Y[3].Event.KeyEvent.wRepeatCount = 1;
00084 inputESC_Y[3].Event.KeyEvent.wVirtualKeyCode =
VkKeyScan(
'y');
00085 inputESC_Y[3].Event.KeyEvent.wVirtualScanCode =
MapVirtualKey(
VkKeyScan(
'y'),0);
00086 inputESC_Y[3].Event.KeyEvent.uChar.AsciiChar =
'y';
00087 inputESC_Y[3].Event.KeyEvent.dwControlKeyState = 0;
00088
00089 retval = WriteConsoleInput( GetStdHandle(
STD_INPUT_HANDLE), &inputESC_Y[0], 4, &dwNumWrites );
00090
00091 printf(
"done: value returned by WriteConsoleOutput was (BOOL)%lx\n", retval);
00092
return 0;
00093 }
00094
00095 printf(
"Using VK_ESCAPE: ");
00096 inputESC_Y[0].EventType = KEY_EVENT;
00097 inputESC_Y[0].Event.KeyEvent.bKeyDown =
TRUE;
00098 inputESC_Y[0].Event.KeyEvent.wRepeatCount = 1;
00099 inputESC_Y[0].Event.KeyEvent.wVirtualKeyCode = VK_ESCAPE;
00100 inputESC_Y[0].Event.KeyEvent.wVirtualScanCode =
MapVirtualKey(VK_ESCAPE,0);
00101 inputESC_Y[0].Event.KeyEvent.uChar.AsciiChar = 27;
00102 inputESC_Y[0].Event.KeyEvent.dwControlKeyState = 0;
00103
00104 inputESC_Y[1].EventType = KEY_EVENT;
00105 inputESC_Y[1].Event.KeyEvent.bKeyDown =
FALSE;
00106 inputESC_Y[1].Event.KeyEvent.wRepeatCount = 1;
00107 inputESC_Y[1].Event.KeyEvent.wVirtualKeyCode = VK_ESCAPE;
00108 inputESC_Y[1].Event.KeyEvent.wVirtualScanCode =
MapVirtualKey(VK_ESCAPE,0);
00109 inputESC_Y[1].Event.KeyEvent.uChar.AsciiChar = 27;
00110 inputESC_Y[1].Event.KeyEvent.dwControlKeyState = 0;
00111
00112 inputESC_Y[2].EventType = KEY_EVENT;
00113 inputESC_Y[2].Event.KeyEvent.bKeyDown =
TRUE;
00114 inputESC_Y[2].Event.KeyEvent.wRepeatCount = 1;
00115 inputESC_Y[2].Event.KeyEvent.wVirtualKeyCode =
VkKeyScan(
'y');
00116 inputESC_Y[2].Event.KeyEvent.wVirtualScanCode =
MapVirtualKey(
VkKeyScan(
'y'),0);
00117 inputESC_Y[2].Event.KeyEvent.uChar.AsciiChar =
'y';
00118 inputESC_Y[2].Event.KeyEvent.dwControlKeyState = 0;
00119
00120 inputESC_Y[3].EventType = KEY_EVENT;
00121 inputESC_Y[3].Event.KeyEvent.bKeyDown =
FALSE;
00122 inputESC_Y[3].Event.KeyEvent.wRepeatCount = 1;
00123 inputESC_Y[3].Event.KeyEvent.wVirtualKeyCode =
VkKeyScan(
'y');
00124 inputESC_Y[3].Event.KeyEvent.wVirtualScanCode =
MapVirtualKey(
VkKeyScan(
'y'),0);
00125 inputESC_Y[3].Event.KeyEvent.uChar.AsciiChar =
'y';
00126 inputESC_Y[3].Event.KeyEvent.dwControlKeyState = 0;
00127
00128 retval = WriteConsoleInput( GetStdHandle(
STD_INPUT_HANDLE), &inputESC_Y[0], 4, &dwNumWrites );
00129
00130 printf(
"done: value returned by WriteConsoleOutput was (BOOL)%lx\n", retval);
00131 }