简体   繁体   中英

How do I close the on-screen keyboard from C# winform and cancel any CTRL or ALT keypresses

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?

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();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM