2

Hi I have an issue with a .NET touchscreen application in Win7 (no PC keyboard connected). I am using part of the app to act as a terminal window to an external device. When the terminal window opens, I start the on screen keyboard by calling:-

string progFiles = @"C:\Program Files\Common Files\Microsoft Shared\ink";
string onScreenKeyboardPath = System.IO.Path.Combine(progFiles, "TabTip.exe");
oskProcess = System.Diagnostics.Process.Start(onScreenKeyboardPath);

After I have finished with the terminal window, I wish to close the form by a single click on the X of the form, which will then automatically close the on screen keyboard. So I call:-

Process[] oskProcessArray = Process.GetProcessesByName("TabTip");
foreach (Process onscreenProcess in oskProcessArray)
{
    onscreenProcess.Kill();
    onscreenProcess.Dispose();
}

This works perfectly, EXCEPT when the last key pressed was either a CTRL, ALT or SHIFT key. If this is the case, these remain "stuck" even after the keyboard is killed. If I restart the on screen keyboard, they are still highlighted.

If I click the red X of the keyboard firstly before closing my form, all is good. But I want/need to close both together by a single click from my code. SO, how do I clear any "stuck" keys when exiting the keyboard automatically, or is there a different way to do this?

AHP
  • 29
  • 2
  • Instead of `onscreenProcess.Kill();`, try `onscreenProcess.CloseMainWindow();`...(not sure if that will make any difference in your target platform and/or target app, but that's the "graceful" way to ask an app to close itself). – Idle_Mind Oct 05 '15 at 16:57
  • Thanks @Idle_Mind . That "unsticks" the CTRL and hides the keyboard. But I need to exit the keyboard. I have tried to use onscreenProcess.CloseMainWindow() to gracefully close the keyboard followed by a onscreenProcess.Kill() to exit the keyboard, but that just reverts back to the CTRL remaining stuck. – AHP Oct 06 '15 at 07:11

1 Answers1

0

OK this seems to fix the issue If I wait for quite a long time (1500ms) then kill the process it all seems to work!!!

Process[] oskProcessArray = Process.GetProcessesByName("TabTip");
foreach (Process onscreenProcess in oskProcessArray)
{
    Application.DoEvents();
    onscreenProcess.CloseMainWindow();
    Application.DoEvents();
    Thread.Sleep(1500);
    onscreenProcess.Kill();
}
AHP
  • 29
  • 2
  • 1
    If someone decides to mark this as un-useful, perhaps they could explain why and give what they think is a better solution. – AHP Oct 07 '15 at 06:58