1

I made a keyboard in Windows.Forms with many Buttons and the content of them are the different characters of the Alphabet like a real keyboard.

Now the problem is when I am using the Keyboard in Windows 7 everything works perfectly. But when I use the Keyboard on the Touchscreen with Windows XP the keyboard writes multiple times the content of the button I just pressed or does not write anything inside of the textbox.

Here is some example code:

Button temp = sender as Button;
SendKeys.SendWait(temp.Text);

I have tried SendKeys.Flush and the

<appSettings>

<add key="SendKeys" value="SendInput"/>
</appSettings>

inside of the app.config

which is the solution here msdn. But it didnt fix the Problem.

What am I doing wrong?

Edit: Now I found out the first letter always works perfectly. After that everything turns awful. Is there something else than SendKeys.Flush that I could try?

  • Ah, a lot of wasted effort. Windows provides an on-screen keyboard application already. All you need is `Process.Start("osk.exe")`. It works perfectly every time, no need for `SendKeys`. – Cody Gray - on strike Jan 11 '12 at 08:07
  • Hi Cody Gray, thank you for your reply. The osk from windows xp is too small for my touchscreen. You can´t change the size of it. – Knut Hansen Jan 11 '12 at 08:09
  • Have you verified the button click events are occuring as expected on the touch device? – Kerry H Jan 11 '12 at 19:33
  • Yes I have. And if the click events were not correct the first letter which I press would not be correct. – Knut Hansen Jan 12 '12 at 07:04

2 Answers2

2

You're losing focus after the first letter... reset focus to the target before calling SendWait.

anon
  • 21
  • 2
-1

The sendkeys function really is not the best of functions. Using the winApi and more specifically PostMessage will prove better.

Here is an example : PostMessage WM_KEYDOWN send multiply keys?

You will be working more directly with the message Queue, but it also means that you will have to handle extra things, such as layout/localization.

Community
  • 1
  • 1
squelos
  • 1,189
  • 6
  • 16