SendInput

Tech-Archive recommends: Fix windows errors by optimizing your registry



Referencing Paul DiLascia's January 2005 C++ Q&A article here:

http://msdn.microsoft.com/msdnmag/issues/05/01/CQA/

He's using SendInput from C++ in the following manner:

static void SendString(LPCTSTR str) {
INPUT inp[2];
memset(inp,0,sizeof(INPUT));
inp[0].type = INPUT_KEYBOARD;
inp[0].ki.dwFlags = KEYEVENTF_UNICODE; // to avoid shift, and so on
inp[1] = inp[0];
inp[1].ki.dwFlags |= KEYEVENTF_KEYUP;

for (LPCTSTR p=str; *p; p++) {
inp[0].ki.wScan = inp[1].ki.wScan = *p;
SendInput(2, inp, sizeof(INPUT));
}
}

I've seen simple C# Interop examples of SendInput (like the one from
pinvoke.net) but none that works with KEYEVENTF_UNICODE. Anyone know how to
get this working properly in C#? I would ideally like something exactly the
C++ SendString method above. I've already tried SendKeys and it doesn't work
correctly for my needs.

Thanks for any help you can provide!


.