I am writing a program, and it is going well so far, however I have an issue with the following code:
void Send(string content) {
unsigned int size = content.size();
INPUT *inputs = new INPUT[size];
for (unsigned int i = 0; i < size; i++) {
inputs[i].type = 1;
inputs[i].ki.wVk = 0;//LOWORD(VkKeyScan(content.at(i)));
inputs[i].ki.wScan = content.at(i);
inputs[i].ki.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_SCANCODE;
inputs[i].ki.time = 0;
inputs[i].ki.dwExtraInfo = ::GetMessageExtraInfo();
}
SendInput(size, inputs, sizeof(*inputs)*size);
for (unsigned int i = 0; i < size; i++) {
inputs[i].ki.dwFlags &= KEYEVENTF_KEYUP;
}
SendInput(size, inputs, sizeof(*inputs)*size);
}
What I am trying to achieve is being able to send input like this:
Send(string("Hello World!"));
However, it does everything it should not, such as moving the cursor even though the type is set to the keyboard. At most, it outputs one character. As you see on line 2, I have an INPUT array. However, when I view this in the debugger, it appears simply as a single INPUT structure, rather than an array of structures.
I am using g++ with gdb debugger + Code::Blocks IDE.
Thanks guys.
EDIT
NEW CODE:
void Send(string content) {
unsigned int size = content.size();
INPUT *inputs = new INPUT[size];
INPUT curr[1];
ZeroMemory(inputs, sizeof(*inputs)*size);
for (unsigned int i = 0; i < size; i++) {
inputs[i].type = 1;
inputs[i].ki.wVk = 0;//LOWORD(VkKeyScan(content.at(i)));
inputs[i].ki.wScan = content.at(i);
inputs[i].ki.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_SCANCODE;
inputs[i].ki.time = 0;
inputs[i].ki.dwExtraInfo = ::GetMessageExtraInfo();
}
for (unsigned int i = 0; i < size; i++) {
curr[0] = inputs[i]; // Current input
int a = ::SendInput(1, (INPUT*)&curr, sizeof(curr));
inputs[i].ki.dwFlags &= KEYEVENTF_KEYUP;
curr[0] = inputs[i];
int b = ::SendInput(1, (INPUT*)&curr, sizeof(curr));
TCHAR *buff = new TCHAR[3];
wsprintf(buff, "%i %i", a, b);
MessageBox(NULL, buff, "SendInput return vals", 0);
}
}
This still sends nothing.
buffand trashing nearby memory in the process.