SendMessage(handle, WM_CHAR, VirtualKeys.VK_A, 0) does not trigger KeyDown...

F

Fred Heida

Hi All,

maybe this is a sill question..but if i have TextBox and use the
SendMessage(..) to send
a character the control.. the KeyDown event is not triggered.... in would
need to check in the WndProc(...) of the WM_CHAR event...

Is there another way to send characters to the TextBox, when I'm only having
the control's handle
which does simulated the user typing in characters so the KeyDown event gets
triggered?

Cheers,

Fred
 
C

Chris Dunaway

If you want the KeyDown event triggered, you need to send the
WM_KEYDOWN message.
 
F

Fred Heida

Hi Chris,

thx...

using the WM_KEYDOWN.. how can i send a control key + a letter.. e.g Ctrl+G
??

Cheers,

Fred
 
C

Chris Dunaway

It appears as if you have to send 5 messages to get a Ctrl+G:

WM_KEYDOWN for the Ctrl key
WM_KEYDOWN for the G key
WM_CHAR for the Ctrl-G (7)
WM_KEYUP for the G key
WM_KEYUP for the Ctrl key

I could be wrong, but that is how it looked in Spy++ when I pressed
Ctrl+G on a textbox.

Here is how I duplicated that in code:

Dim GDownLParam As New IntPtr(&H220001)
Dim GUpLParam As New IntPtr(&HC0220001)
Dim CtrlDownLParam As New IntPtr(&H11D0001)
Dim CtrlUpLParam As New IntPtr(&HC11D0001)
Win32.User.SendMessage(TextBox1.Handle, Win32.User.WM_KEYDOWN,
&H11, CtrlDownLParam)
Win32.User.SendMessage(TextBox1.Handle, Win32.User.WM_KEYDOWN,
&H47, GDownLParam)
Win32.User.SendMessage(TextBox1.Handle, Win32.User.WM_CHAR,
&H7, GDownLParam)
Win32.User.SendMessage(TextBox1.Handle, Win32.User.WM_KEYUP,
&H47, GUpLParam)
Win32.User.SendMessage(TextBox1.Handle, Win32.User.WM_KEYUP,
&H11, CtrlUpLParam)

I have a set of classes that make it easy to call the Win32 API and
that is what I am using in this code. If you're interested in those
classes, I can send them.

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top