KeyPress simulate

  • Thread starter Thread starter Maxim
  • Start date Start date
M

Maxim

Hello, everybody!

I would like to simulate keybord input to a TextBox. I have tried the
following method. Created a new custom MyTextBox that inherits TextBox. The
new component contains only one additional method DoKeyPress which calls
base OnKeyPress method. I've tried to simulate keybord input by calling this
new method. But nothing apppears on the TextBox. What's wrong?

Thanks in advance.
 
The text box isn't a real Windows control. It's layered on top of the real
control. So, it's the Windows control that is actually receiving the
keyboard input, adding it to the right place in the string, etc. The result
of doing that is the call to DoKeyPress(). You might use keybd_event() or
PostKeybdMessage() to send keyboard data to the Windows CE input system
where it will be dispatched to whatever control in whatever application has
the focus, maybe to your control, or you could try sending WM_CHAR messages
to the control itself.

Paul T.
 
Or, I should say that the result is a call to *OnKeyPress*, not
DoKeyPress...

Paul T.

"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:[email protected]...
 
Thank you for help, Paul.

So, if I understood correctly, to simulate an input I need to use Native API
calls. And there is no way to do it using .NET classes. Correct?



"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
 
You can always P/Invoke.

-Chris


Maxim said:
Thank you for help, Paul.

So, if I understood correctly, to simulate an input I need to use Native
API
calls. And there is no way to do it using .NET classes. Correct?



"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
The text box isn't a real Windows control. It's layered on top of the real
control. So, it's the Windows control that is actually receiving the
keyboard input, adding it to the right place in the string, etc. The result
of doing that is the call to DoKeyPress(). You might use keybd_event()
or
PostKeybdMessage() to send keyboard data to the Windows CE input system
where it will be dispatched to whatever control in whatever application has
the focus, maybe to your control, or you could try sending WM_CHAR messages
to the control itself.

Paul T.
 
Yes you have to use keybd_event P/Invoke or use
OpenNETCF.Windows.Forms.SendKeys from SDF [1] which behaves like
System.Windows.Forms.SendKeys from Full Framework [2].


[1] http://www.opennetcf.org/sdf/
[2] http://msdn2.microsoft.com/library/k3w7761b.aspx


--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com

Thank you for help, Paul.

So, if I understood correctly, to simulate an input I need to use Native API
calls. And there is no way to do it using .NET classes. Correct?



"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
The text box isn't a real Windows control. It's layered on top of the real
control. So, it's the Windows control that is actually receiving the
keyboard input, adding it to the right place in the string, etc. The result
of doing that is the call to DoKeyPress(). You might use keybd_event() or
PostKeybdMessage() to send keyboard data to the Windows CE input system
where it will be dispatched to whatever control in whatever application has
the focus, maybe to your control, or you could try sending WM_CHAR messages
to the control itself.

Paul T.
 
Back
Top