Hello

I'm using the SendKeys.Send method for an onscreen keyboard. This works
perfect except one problem:

If i configure windows to use an english keyboard the call
SendKeys.Send("{^}") results in a "^".
BUT when my computer is running with an german keyboard, the call
SendKeys.Send("{^}") results in a "&".

MSDN says: If your application is intended for international use with a
variety of keyboards, the use of Send could yield unpredictable results and
should be avoided.

Okay that sounds bad, the strange thing is that every other keystroke (or
text) is working fine, excepts the "^" character.

Berni

RE: SendKeys.Send Problem by jetan

jetan
Wed Apr 30 23:13:09 CDT 2008

Hi Berni,

I am not familiar with the german keyboard, so it is hard for me say the
root cause without reproducing the problem. Is it possible that only "^" is
translated into "&" on german keyboard?

Actually, using SendKeys.Send is not operating the on-screen keyboard, it
is sending keystrokes through the real keyboard input queue, so it will be
affected by the real keyboard settings instead of the on-screen keyboard.
That's why MSDN placed a "Caution" for SendKeys.Send() method.

Can you help to explain what you want to achieve? Maybe we have other
solution to workaround this problem. If you just want to send characters to
a TextBox in an application(or your own application), the simplest solution
is calling SendMessage(WM_CHAR) to that control/window. In the "wParam" of
SendMessage API, we may specify the character ASCII code. For example, we
may specify 94(0x5E) for "wParam" for "^" character. The link below
contains the ASCII character table:
"ASCII Character Codes Chart 1"
http://msdn.microsoft.com/en-us/library/60ecse8t.aspx

Actually, even we are using SendKeys.Send, the target application will just
receive a WM_LBUTTONDOWN message for the real keyboard button, which will
finally be translated into WM_CHAR by Winform/Win32 code. So, using WM_CHAR
is a more straightforward solution.

If you want to take this approach and need further help, please feel free
to tell me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


RE: SendKeys.Send Problem by jetan

jetan
Sun May 04 22:21:32 CDT 2008

Hi Berni,

Have you reviewed my reply to you? Does it make sense to you? If you still
need any help or have any concern, please feel free to tell me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=========================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.


Re: SendKeys.Send Problem by Berni

Berni
Mon May 05 03:00:42 CDT 2008

Hi Jeffrey,

Thank you for your reply! I think the solution with the WM_CHAR message
could to the job. I have an application that is written for a touch screen
based terminal (without a keyboard). We will display HTML content inside the
webbrowser control.

So we need an on screen keyboard that allows the user to type some text to
text boxes. I will test the WM_CHAR method and let you know if this solves
the problem.

Berni



Re: SendKeys.Send Problem by jetan

jetan
Mon May 05 03:33:54 CDT 2008

Hi Berni,

Thank you for the confirmation.

Ok, if you need any further help, please feel free to feedback, I am glad
to be any help. Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=========================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.


Re: SendKeys.Send Problem by Berni

Berni
Mon May 05 04:35:32 CDT 2008

Hello

Okay the "WM_CHAR" message does not work for me (i think). My application
uses a WebBrowser control to display a HTML page. I would like to type text
to a text input inside this HTML page. With the SendKeys.Send method this is
no problem (except the "^" problem of course). With WM_CHAR it only works if
i send the message to a TextBox control. But if i send the WM_CHAR message
to the WebBrowser control it does not work.

Berni



Re: SendKeys.Send Problem by jetan

jetan
Tue May 06 21:26:37 CDT 2008

Hi Berni,

Thanks for your feedback.

It is hard to get it working with WebBrowser control because WebBrowser is
a complex control and it is composed with several child controls in it. So
if we send WM_CHAR to the outer WebBrowser control, it will not display the
character in the inner control's text input field.

SendKeys.Send is not the perfect solution here for the following reasons:
1. The original international keyboard issue
2. If the user switches the focus to another application/windows,
SendKeys.Send will falsely send keystroke to the wrong control/window.

Fortunately, WebBrowser provides a rich set of interface to manipulate the
elements in it. Using the build-in programming model of WebBrowser control
should be the ideal solution. The solution logic is easy:
1. Getting the HtmlDocument of the WebBrowser control.
2. Get the currently focused control by using HtmlDocument.ActiveElement.
3. Set its InnerText to the desired value.

The following code snippet demonstrates the logic:

private void Form1_Load(object sender, EventArgs e)
{
this.webBrowser1.Navigate("http://www.google.com");
}

private void button1_Click(object sender, EventArgs e)
{
if (webBrowser1.Document != null)
{
HtmlDocument hd = webBrowser1.Document;
HtmlElement currentFocusedElement = hd.ActiveElement;
if( currentFocusedElement!=null)
{
currentFocusedElement.InnerText = "This is a test";
}
}
}

It works well on my side. Hope it meets your need. Thanks.


Best regards,
Jeffrey Tan
Microsoft Online Community Support
=========================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.


RE: SendKeys.Send Problem by Betty

Betty
Thu May 08 05:07:02 CDT 2008

Hi Jeffrey,
I've read your following comments and wrote some codes (C#). But they don't
work correctly. Please have a look. Thank you a lot.

[DllImport("User32.dll")]
internal static extern Int32 SendMessage(IntPtr hWnd, int Msg, IntPtr
wParam, IntPtr lParam);
/*handle is present an edit box. I want to use SendMessage to type a char
into this edit, but nothing is input into it.*/
SendMessage(handle, 0x0100, (IntPtr)0x61, (IntPtr)0);


""Jeffrey Tan[MSFT]"" wrote:

> Hi Berni,
>
> I am not familiar with the german keyboard, so it is hard for me say the
> root cause without reproducing the problem. Is it possible that only "^" is
> translated into "&" on german keyboard?
>
> Actually, using SendKeys.Send is not operating the on-screen keyboard, it
> is sending keystrokes through the real keyboard input queue, so it will be
> affected by the real keyboard settings instead of the on-screen keyboard.
> That's why MSDN placed a "Caution" for SendKeys.Send() method.
>
> Can you help to explain what you want to achieve? Maybe we have other
> solution to workaround this problem. If you just want to send characters to
> a TextBox in an application(or your own application), the simplest solution
> is calling SendMessage(WM_CHAR) to that control/window. In the "wParam" of
> SendMessage API, we may specify the character ASCII code. For example, we
> may specify 94(0x5E) for "wParam" for "^" character. The link below
> contains the ASCII character table:
> "ASCII Character Codes Chart 1"
> http://msdn.microsoft.com/en-us/library/60ecse8t.aspx
>
> Actually, even we are using SendKeys.Send, the target application will just
> receive a WM_LBUTTONDOWN message for the real keyboard button, which will
> finally be translated into WM_CHAR by Winform/Win32 code. So, using WM_CHAR
> is a more straightforward solution.
>
> If you want to take this approach and need further help, please feel free
> to tell me, thanks.
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Community Support
>
> Delighting our customers is our #1 priority. We welcome your comments and
> suggestions about how we can improve the support we provide to you. Please
> feel free to let my manager know what you think of the level of service
> provided. You can send feedback directly to my manager at:
> msdnmg@microsoft.com.
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> ications.
>
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscriptions/support/default.aspx.
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>

RE: SendKeys.Send Problem by Betty

Betty
Thu May 08 05:21:00 CDT 2008

/*The following two lines of codes cannot work correctly too.*/
SendMessage(handle, 0x0101, (IntPtr)0x61, (IntPtr)0);
SendMessage(handle, 0x0102, (IntPtr)0x61, (IntPtr)0);

"Betty" wrote:

> Hi Jeffrey,
> I've read your following comments and wrote some codes (C#). But they don't
> work correctly. Please have a look. Thank you a lot.
>
> [DllImport("User32.dll")]
> internal static extern Int32 SendMessage(IntPtr hWnd, int Msg, IntPtr
> wParam, IntPtr lParam);
> /*handle is present an edit box. I want to use SendMessage to type a char
> into this edit, but nothing is input into it.*/
> SendMessage(handle, 0x0100, (IntPtr)0x61, (IntPtr)0);
>
>
> ""Jeffrey Tan[MSFT]"" wrote:
>
> > Hi Berni,
> >
> > I am not familiar with the german keyboard, so it is hard for me say the
> > root cause without reproducing the problem. Is it possible that only "^" is
> > translated into "&" on german keyboard?
> >
> > Actually, using SendKeys.Send is not operating the on-screen keyboard, it
> > is sending keystrokes through the real keyboard input queue, so it will be
> > affected by the real keyboard settings instead of the on-screen keyboard.
> > That's why MSDN placed a "Caution" for SendKeys.Send() method.
> >
> > Can you help to explain what you want to achieve? Maybe we have other
> > solution to workaround this problem. If you just want to send characters to
> > a TextBox in an application(or your own application), the simplest solution
> > is calling SendMessage(WM_CHAR) to that control/window. In the "wParam" of
> > SendMessage API, we may specify the character ASCII code. For example, we
> > may specify 94(0x5E) for "wParam" for "^" character. The link below
> > contains the ASCII character table:
> > "ASCII Character Codes Chart 1"
> > http://msdn.microsoft.com/en-us/library/60ecse8t.aspx
> >
> > Actually, even we are using SendKeys.Send, the target application will just
> > receive a WM_LBUTTONDOWN message for the real keyboard button, which will
> > finally be translated into WM_CHAR by Winform/Win32 code. So, using WM_CHAR
> > is a more straightforward solution.
> >
> > If you want to take this approach and need further help, please feel free
> > to tell me, thanks.
> >
> > Best regards,
> > Jeffrey Tan
> > Microsoft Online Community Support
> >
> > Delighting our customers is our #1 priority. We welcome your comments and
> > suggestions about how we can improve the support we provide to you. Please
> > feel free to let my manager know what you think of the level of service
> > provided. You can send feedback directly to my manager at:
> > msdnmg@microsoft.com.
> >
> > ==================================================
> > Get notification to my posts through email? Please refer to
> > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> > ications.
> >
> > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> > where an initial response from the community or a Microsoft Support
> > Engineer within 1 business day is acceptable. Please note that each follow
> > up response may take approximately 2 business days as the support
> > professional working with you may need further investigation to reach the
> > most efficient resolution. The offering is not appropriate for situations
> > that require urgent, real-time or phone-based interactions or complex
> > project analysis and dump analysis issues. Issues of this nature are best
> > handled working with a dedicated Microsoft Support Engineer by contacting
> > Microsoft Customer Support Services (CSS) at
> > http://msdn.microsoft.com/subscriptions/support/default.aspx.
> > ==================================================
> > This posting is provided "AS IS" with no warranties, and confers no rights.
> >
> >

Re: SendKeys.Send Problem by Berni

Berni
Thu May 08 09:09:41 CDT 2008

Hi Jeffrey,

Thank you for your help. Your solution with the HtlmDocument and
ActiveElement ist cool, i like it!

Your sample made me smile! It's funny that you use www.google.com in your
code and not www.live.com ;)

Benri


""Jeffrey Tan[MSFT]"" <jetan@online.microsoft.com> schrieb im Newsbeitrag
news:Gl3tRn%23rIHA.772@TK2MSFTNGHUB02.phx.gbl...
> Hi Berni,
>
> Thanks for your feedback.
>
> It is hard to get it working with WebBrowser control because WebBrowser is
> a complex control and it is composed with several child controls in it. So
> if we send WM_CHAR to the outer WebBrowser control, it will not display
> the
> character in the inner control's text input field.
>
> SendKeys.Send is not the perfect solution here for the following reasons:
> 1. The original international keyboard issue
> 2. If the user switches the focus to another application/windows,
> SendKeys.Send will falsely send keystroke to the wrong control/window.
>
> Fortunately, WebBrowser provides a rich set of interface to manipulate the
> elements in it. Using the build-in programming model of WebBrowser control
> should be the ideal solution. The solution logic is easy:
> 1. Getting the HtmlDocument of the WebBrowser control.
> 2. Get the currently focused control by using HtmlDocument.ActiveElement.
> 3. Set its InnerText to the desired value.
>
> The following code snippet demonstrates the logic:
>
> private void Form1_Load(object sender, EventArgs e)
> {
> this.webBrowser1.Navigate("http://www.google.com");
> }
>
> private void button1_Click(object sender, EventArgs e)
> {
> if (webBrowser1.Document != null)
> {
> HtmlDocument hd = webBrowser1.Document;
> HtmlElement currentFocusedElement = hd.ActiveElement;
> if( currentFocusedElement!=null)
> {
> currentFocusedElement.InnerText = "This is a test";
> }
> }
> }
>
> It works well on my side. Hope it meets your need. Thanks.
>
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Community Support
> =========================================
> Delighting our customers is our #1 priority. We welcome your comments and
> suggestions about how we can improve the support we provide to you. Please
> feel free to let my manager know what you think of the level of service
> provided. You can send feedback directly to my manager at:
> msdnmg@microsoft.com.
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>



Re: SendKeys.Send Problem by jetan

jetan
Thu May 08 21:09:21 CDT 2008

Hi Berni,

Glad to see my reply can help you.

WM_CHAR works for most of the Windows build-in controls pretty well.
However, WebBrowser is a special control with complex internal structure,
so WM_CHAR may not work for it. Since WebBrowser control uses the core
engine of IE, we may leverage the IE DOM to manipulate the html elements in
WebBrowser control.

Yes, it is my personal favorite search engine :-). If you need any further
help, please feel free to tell me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=========================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.