Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 842981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:03:09+00:00 2026-05-15T06:03:09+00:00

I start the Windows On-Screen-Keyboard like that: s_onScreenKeyboard = new Process(); s_onScreenKeyboard.StartInfo = new

  • 0

I start the Windows On-Screen-Keyboard like that:

s_onScreenKeyboard = new Process();
s_onScreenKeyboard.StartInfo = new ProcessStartInfo("osk.exe");
s_onScreenKeyboard.EnableRaisingEvents = true;
s_onScreenKeyboard.Exited += new EventHandler(s_onScreenKeyboard_Exited);
s_onScreenKeyboard.Start();

This works fine, but when I try to stop it using the following code, it does not work, i.e. the OSK keeps running and the method returns false:

s_onScreenKeyboard.CloseMainWindow();
if (!s_onScreenKeyboard.HasExited)
{
    if (!s_onScreenKeyboard.WaitForExit(1000))
    {
        s_onScreenKeyboard.Close();
        //s_onScreenKeyboard.Kill();
    }
}

When uncommenting s_onScreenKeyboard.Kill(); it is closed, but the problem is that osk.exe obviously uses another process called “msswchx.exe” which is not closed if I simply kill the OSK process. This way, I would end up with hundreds of these processes which is not what I want.

Another strange thing is that the CloseMainWindow() call worked at some time, but then it suddenly did not work anymore, and I do not remember what has changed.

Any ideas?

EDIT: I have found a solution myself. Please see my answer for details.

Background:
I am implementing an On-Screen-Keyboard for my application because it should work with a touchscreen. It is important that the keyboard layout matches the layout which is configured in Windows since the application will be shipped to many different countries. Therefore, instead of implementing a custom keyboard control with approx. 537 keyboard layouts (exaggerating a little here…), I wanted to utilize the Windows built-in On-Screen-Keyboard which adapts to the selected keyboard layout automatically, saving a lot of work for me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:03:10+00:00Added an answer on May 15, 2026 at 6:03 am

    I have found the/a solution myself:

    When I successfully retrieve the MainWindowHandle after the process has been started, the call to CloseMainWindow() is also successful later on. I do not understand the reason for this, but the important thing is: it works!

    BTW, for others having the same problem: The MainWindowHandle is not available immediately after starting the process. Obviously, it takes some milliseconds until the MainWindow is started which is why I use the following code to retrieve the handle:

    DateTime start = DateTime.Now;
    IntPtr handle = IntPtr.Zero;
    
    while (handle == IntPtr.Zero && DateTime.Now - start <= TimeSpan.FromSeconds(2))
    {
        try
        {
            // sleep a while to allow the MainWindow to open...
            System.Threading.Thread.Sleep(50);
            handle = s_onScreenKeyboard.MainWindowHandle;
        }
        catch (Exception) { }
    }
    

    In this code I continuously get the MainWindowHandle every ~50ms as long as it is still equal to IntPtr.Zero. If the handle could not be retrieved after 2 seconds, I quit the loop to avoid an endless loop in case of error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'll start working on windows forms application that hosts ESRI maps into it So,
I will start new PDA project on the windows mobile and compact framework 2.0
I'm going to implementing an On Screen Keyboard for Window which requires the OSK
We're building a touch screen kiosk application that will run on Windows POS Ready
Is there a way to programmatically open and show the Windows 7 on-screen keyboard
From within a screen session, I'd like to run a shell script that opens
When I look at the start screen of my Windows 8 installation I see
I have a document-based Cocoa application that has to start up a sub-process before
Where can I start learning Windows Form designing? For example: Microsoft Zune player, Buttons,
How can I make a quick start on Windows Phone 7 in working with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.