Hi,
Firstly, this is Win32 console related, otherwise I'd be reading up on the ncurses library..
My program is updating name:value pairs like Name:John
I wish to use WriteConsoleInput to inject the current value into the inputstream so that the user can edit the characters rather than start again. this is definetly in the realms of showy code, but I'm interested in how easy this could be.
When I run the following code, instead of the string value being inputted to the input stream I see ??. I can't tell if the problem is code page related, a stupid error on my part, or something else ( or all of the above :-) )
I should say that the fillBuff function returns what looks like a valid array of INPUT_RECORDS, 2 for each character of value (keydown & keyup).
code extract:
INPUT_RECORD fillBuff(std::string value) {
size_t len = value.length();
int y = 0;
/*INPUT_RECORD *irec = new INPUT_RECORD[(2*len)-1];*/
INPUT_RECORD irec[10];
for (int i=0; i < (2*len)-1; i+=2) {
irec[i].EventType = KEY_EVENT;
irec[i].Event.KeyEvent.bKeyDown = TRUE;
irec[i].Event.KeyEvent.dwControlKeyState = 0;
irec[i].Event.KeyEvent.uChar.AsciiChar = int(value[y]);
irec[i].Event.KeyEvent.wRepeatCount = 1;
irec[i].Event.KeyEvent.wVirtualKeyCode = (value[y]); /* virtual keycode is always uppercase */
irec[i].Event.KeyEvent.wVirtualScanCode = MapVirtualKeyA(irec[i].Event.KeyEvent.wVirtualKeyCode & 0x00ff, 0);
irec[i+1].EventType = KEY_EVENT;
irec[i+1].Event.KeyEvent.bKeyDown = FALSE;
irec[i+1].Event.KeyEvent.dwControlKeyState = 0;
irec[i+1].Event.KeyEvent.uChar.AsciiChar = int(value[y]);
irec[i+1].Event.KeyEvent.wRepeatCount = 1;
irec[i+1].Event.KeyEvent.wVirtualKeyCode = toupper(value[y]);
irec[i+1].Event.KeyEvent.wVirtualScanCode = MapVirtualKeyA(irec[i+1].Event.KeyEvent.wVirtualKeyCode & 0x00ff, 0);
y++;
}
return irec[0];
}
/***********************************************************/
int main(int argc, char *argv[]) {
string in;
string value = "aBCD";
HANDLE conIn;
DWORD dw;
size_t len = value.length();
conIn = GetStdHandle(STD_INPUT_HANDLE);
INPUT_RECORD *records;
records = &fillBuff(value);
WriteConsoleInput(conIn, records, len , &dw);
in = getchar();
return 0;
}