Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sending key strokes from my App to another

0 views
Skip to first unread message

Joe

unread,
Dec 16, 2009, 1:05:59 AM12/16/09
to
I can't seem to get this figured out.

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?

r_z_...@pen_fact.com

unread,
Dec 16, 2009, 4:11:13 PM12/16/09
to
On Wed, 16 Dec 2009 01:05:59 -0500, Joe <joe.g...@nonebusiness.com>
wrote:

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

0 new messages