7

I want to start the new On-Screen-Keyboard (OSK) using code. You can find this one in the taskbar:

New-OSK-Taskbar

(if not there you find it by right clicking the taskbar).

I have already tried the regular:

System.Diagnostics.Process.Start("osk.exe");

But I want to start the other one (not in window mode). Here you see which OSK I want and which one not:

OSK wanted version distinction

How can I start that version? And how can I start it in a certain setting (if possible)?

Corentin Pane
  • 4,794
  • 1
  • 12
  • 29
GionSnow
  • 117
  • 1
  • 10
  • 1
    Unless this is related to a very recent version of Windows that I'm not aware of, this isn't a "new OSK". This is just the touch keyboard that is available only while in tablet-mode; it has been the case for along time. I edited your question title. Feel free to roll the edit back or edit further if this doesn't reflect what you're after. – 41686d6564 stands w. Palestine Nov 07 '19 at 11:01

1 Answers1

4

By starting a process in command-line

I believe you want to start the following process in Windows 10, as suggested here:

"C:\Program Files\Common Files\microsoft shared\ink\tabtip.exe"

As suggested by @bernard-vander-beken, it's better to use

Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles)

to produce the "C:\Program Files\Common Files\" part of the path to fit different install locations.

Through an API

The previous command-line seems to work in inconsistent ways, in particular it doesn't work twice if the tabtip.exe process is already running.

I found this snippet by @torvin on this thread, which you can use to programmatically show the on-screen keyboard after you've started the tabtip.exe using the command-line solution, otherwise it fails with a COM exception.

class Program
{
    static void Main(string[] args)
    {
        var uiHostNoLaunch = new UIHostNoLaunch();
        var tipInvocation = (ITipInvocation)uiHostNoLaunch;
        tipInvocation.Toggle(GetDesktopWindow());
        Marshal.ReleaseComObject(uiHostNoLaunch);
    }

    [ComImport, Guid("4ce576fa-83dc-4F88-951c-9d0782b4e376")]
    class UIHostNoLaunch
    {
    }

    [ComImport, Guid("37c994e7-432b-4834-a2f7-dce1f13b834b")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    interface ITipInvocation
    {
        void Toggle(IntPtr hwnd);
    }

    [DllImport("user32.dll", SetLastError = false)]
    static extern IntPtr GetDesktopWindow();
}
Corentin Pane
  • 4,794
  • 1
  • 12
  • 29
  • 2
    To make it work with diferrent install locations, consider using the special folder API. E.g. Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles). Source: https://learn.microsoft.com/en-us/dotnet/api/system.environment.specialfolder?view=netframework-4.8 https://stackoverflow.com/questions/32588217/whats-the-specialfolder-enum-member-that-has-the-base-directory-for-the-user – Bernard Vander Beken Nov 07 '19 at 10:57
  • Thanks what you suggested seems to be the correct thing. However if I try to start the _tabtip.exe_ nothing happens. (Tried also by starting it manually from the folder) The keyboard icon on the taskbar still works however and starts it correctly. Is there something else that I need to start the _tabtip.exe_? – GionSnow Nov 07 '19 at 12:34
  • are you in tablet mode? Also you might need to start it as admin according to the linked post. Not sure why though. – Corentin Pane Nov 07 '19 at 12:40
  • Somehow starting as admin also did not work for me. Do you have any idea what else it could be? – GionSnow Nov 07 '19 at 12:53
  • 1
    @GionSnow I edited my answer with more research. I'm still not satisfied as it's a bit hacky and undocumented but it might help you. – Corentin Pane Nov 07 '19 at 13:03