Friday, January 11, 2013

Open On-Screen Keyboard In C#


There are some of the ways to on-screen keyboard:
1 - Process.Start("C:\Windows\System32\OSK.EXE")
2 - System.Diagnostics.Process.Start("osk");
3 -Process[] pArr = Process.GetProcesses();
   foreach (Process p in pArr)
   {
            if (p.ProcessName == "osk" || p.ProcessName == "msswchx")
              p.Kill();
   }
ProcessStartInfo pInfo = new ProcessStartInfo(((Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\osk.exe")));              
                Process pr = Process.Start(pInfo);
               System.Threading.Thread.Sleep(100);
                pr.WaitForInputIdle();
4-   string windir = Environment.GetEnvironmentVariable("WINDIR");
            string osk = null;
            if (osk == null)
            {
                osk = Path.Combine(Path.Combine(windir, "system32"), "osk.exe");
                if (!File.Exists(osk))
                {
                    osk = null;
                }
            }
            if (osk == null)
                osk = "osk.exe";

            Process.Start(osk);

but when you have 32-bit built application and you want to open osk on 64-bit Windows 7. It will give error "Could not start On-Screen keyboard".  Simply you have to build your application's every module with Any CPU Setting, then this issue will be resolved immediately.

Windows won't allow you to call a 64-bit OSK.exe from your program. Anyone can start osk.exe from Run, but call it from within a 32-bit application won't work in 64-bit Windows.
Ideally Microsoft should include a 32-bit version of OSK.exe in the system folder and allow us to use it, if being called from a 32-bit application.
Another work around is to get your hands on 32-bit Windows XP and pull osk.exe from it, bundle this with you app. When you call the on-screen keyboard, check if OS is 64-bit, if it is call the Windows XP osk.exe, works OK. Although not ideal.

1 comment:

  1. http://humrahimcs.wordpress.com/2013/04/09/keyboard-on-the-screen-in-winforms/

    this link working fine..Error not Occure

    ReplyDelete