I have a small application that needs to send keystrokes to another. I
find it's hWnd using EnumWindows via coredll and PInvoke.
I then use the following code:
[System.Runtime.InteropServices.DllImport("coredll.dll")]
public static extern bool PostKeybdMessage( IntPtr hwnd, uint vKey,
uint KeyStateFlags, uint cCharacters, uint[] pShiftStateBuffer, uint[]
pCharacterBuffer );
uint[] buf = new uint[1];
uint[] States = new uint[1];
States[0] = 0x1;
buf[0] = 65;
PostKeybdMessage(OtherhWnd, 0, 0x1, (uint)buf1.Length, States, buf);
This should be sending an 'A' to other application. I'm not getting
an error, but the application isn't getting the keystroke.
Any ideas?
Two different approaches. The keybd_event function will send keyboard
strokes to whatever application has focus. If what you really want is
characters, rather than keyboard events, you can use WM_CHAR messages
to send strings; I've found that many programs that accept keyboard
input actually accept WM_CHAR messages.
-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).
Robert E. Zaret, eMVP
PenFact, Inc.
20 Park Plaza, Suite 400
Boston, MA 02116
www.penfact.com