views:

184

answers:

1

The return value is 4 and I'm running Visual Studio in administrative mode so permissions should be ok. I don't see anything typed out though. Any help? I'm using Windows 7 x64.

INPUT input[4];

input[0].type = INPUT_KEYBOARD;
input[0].ki.wVk = 0;
input[0].ki.wScan = 'a';
input[0].ki.dwFlags = KEYEVENTF_SCANCODE;
input[0].ki.time = 0;
input[0].ki.dwExtraInfo = 0;

input[1].type = INPUT_KEYBOARD;
input[1].ki.wVk = 0;
input[1].ki.wScan = 'a';
input[1].ki.dwFlags = KEYEVENTF_KEYUP | KEYEVENTF_SCANCODE;
input[1].ki.time = 0;
input[1].ki.dwExtraInfo = 0;

input[2].type = INPUT_KEYBOARD;
input[2].ki.wVk = 0;
input[2].ki.wScan = 'a';
input[2].ki.dwFlags = KEYEVENTF_SCANCODE;
input[2].ki.time = 0;
input[2].ki.dwExtraInfo = 0;

input[3].type = INPUT_KEYBOARD;
input[3].ki.wVk = 0;
input[3].ki.wScan = 'a';
input[3].ki.dwFlags = KEYEVENTF_KEYUP | KEYEVENTF_SCANCODE;
input[3].ki.time = 0;
input[3].ki.dwExtraInfo = 0;

int retval = SendInput(4, input, sizeof(INPUT));
if(retval > 0)
{
  wxLogDebug("SendInput sent %i", retval);
}
else
{
  wxLogError("Unable to send input commands. Error is: %i", GetLastError());
}
A: 

You need to send both KeyDown and KeyUp events for each key.
To send a KeyUp event, set dwFlags to KEYEVENTF_KEYUP.

Also, you need to use wVk instead of wScan. (wScan is only used with KEYEVENTF_UNICODE)

SLaks
That was it. Thanks.
asmw
Which one was it?
SLaks
I changed the flag to KEYEVENTF_UNICODE and it worked with the scancode. The up event isn't required actually though the example I showed had it.
asmw