Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Windows On-Screen Keyboard in C# WinForms

  • VS 2010
  • Developing 32-bit app that runs on 64-bit OS (Windows 7, Windows 8 - desktop app)
  • C#
  • .NET 4.0
  • WinForms

I have found many threads on launching the Windows on-screen keyboard (osk.exe) from an application, but I am running into some problems. It appears to be because I am running a 32-bit app on a 64-bit OS. I've tried the code posted by WooCaSh here: Keyboard on the screen in WinForms

But none of the three different paths work for me. For the sysnative path, Process.Start fails with "Cannot find the path specified." For the system32 and osk.exe paths, I get the "Could not start the on-screen keyboard" error dialog.

I found a possible workaround here, which is a little more complicated than what I was looking for (post by eryang): http://social.msdn.microsoft.com/Forums/en-US/netfx64bit/thread/10ebc62f-e6d7-4072-9fd1-ea3784a0966f/

  1. Is there an easier or correct way to do this?
  2. I was hoping that running my app on a tablet would automatically launch the on-screen keyboard when the user selects a textbox, but no luck. Is this normal or am I missing something? I've found that the keyboard is not automatically launched in Windows 8 when in Desktop mode (which my app is): http://www.bleepingcomputer.com/forums/t/480250/keyboard-does-not-pop-up-automatically/ Apparently it works on Windows 7 tablets, but I can't test because I only have Windows 8 tablets here.
like image 876
Tara Avatar asked Mar 21 '13 17:03

Tara


People also ask

What is the shortcut key for On-Screen Keyboard?

The fastest way to open the on-screen keyboard in Windows 10 is the shortcut [Windows] + [Ctrl] + [O]. This way, the on-screen keyboard can be activated immediately if a physical keyboard is available or intact.

How do I open the On-Screen Keyboard without a keyboard?

Select “Control Panel.” In the Control Panel window, click “Ease of Access,” click “Ease of Access Center,” and then click “Start On-Screen Keyboard.” You can pin the keyboard to your taskbar to access it more easily in the future, if you like.


2 Answers

I am now launching the "Touch Keyboard" as opposed to the "On-Screen Keyboard" (which is the keyboard I wanted on Windows 8 anyway) with:

string progFiles = @"C:\Program Files\Common Files\Microsoft Shared\ink";
string keyboardPath = Path.Combine(progFiles, "TabTip.exe");

this.keyboardProc = Process.Start(keyboardPath);

This works on my Win7 and Win8, regardless of my 32-bit app on 64-bit OS. However, I still have the problem of programmatically closing the keyboard when I'm done. The process, this.keyboardProc, does not seem to get the handle, and immediately has property HasExited = true. This means my attempts to close or kill it fail.

According to this thread, if the user manually opens the keyboard (or I programmatically launch it), the keyboard will not automatically close/hide when the text field loses focus: Windows 8 - How to Dismiss Touch Keyboard? I tried the workaround of setting the focus to a hidden button, but since I launched the keyboard myself, it doesn't close automatically.

like image 163
Tara Avatar answered Oct 14 '22 04:10

Tara


I had trouble closing the on screen keyboard. You can start the Touch Keyboard with

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

and close all keyboards with

//Kill all on screen keyboards
Process[] oskProcessArray = Process.GetProcessesByName("TabTip");
foreach (Process onscreenProcess in oskProcessArray)
{
    onscreenProcess.Kill();
}

For some reason onScreenKeyboardProc.Kill() or .Close() doesn't work.

like image 27
Panu Horsmalahti Avatar answered Oct 14 '22 03:10

Panu Horsmalahti