1

You can open the Windows 10 on-screen keyboard from C# code using:

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

Is there a way in C# to dock this keyboard to the bottom of the screen when opened?
I need to create the same effect that 'dock' button does on the onscreen keyboard itself.

GSerg
  • 76,472
  • 17
  • 159
  • 346
salveiro
  • 419
  • 1
  • 5
  • 13
  • You can try this https://www.codeproject.com/Articles/9123/Hosting-EXE-Applications-in-a-WinForm-project – Ozan Gunceler Jan 04 '19 at 18:17
  • Pleas see: https://blogs.msdn.microsoft.com/toub/2006/05/03/low-level-keyboard-hook-in-c/. may be help you. – isaeid Jan 04 '19 at 18:26
  • There are two on-screen-keyboards in Windows 8+, osk.exe is the old one from Windows 2000/XP. – Anders Jan 04 '19 at 18:32
  • Win10 uses a very different way to display the OSK, so olden hacks are not going to work anymore. It is not much of a practical problem, the user simply clicks "Mv Dn" once and that's it, it remembers where it was displayed last. – Hans Passant Jan 04 '19 at 18:57

1 Answers1

4

osk.exe supports a undocumented command line parameter /dockbottom. However, running osk.exe /dockbottom just places the keyboard at the bottom of your screen, it is not exactly the same as docking. I don't know how far back this parameter works but I confirmed it works in Windows 8 and 10.

I don't think there is a way to actually dock (app bar docking) programmatically. Faking a click on the UI button might work but you would have to use UI Automation because it is not a real button, the whole window is a DirectUIHWND window.

As a hack you can set a REG_DWORD called Dock to 1 under HKEY_CURRENT_USER\Software\Microsoft\Osk and HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Accessibility\ATConfig\osk (this is a volatile key so you must open it as such) while osk.exe is not running. When you start it again it will read the dock setting and start docked.

Note: This docking mode is not available if the screen resolution is set too low.

Windows 8 and later also have a different on-screen-keyboard called the touch keyboard. You can control this keyboard with IFrameworkInputPane.

Anders
  • 97,548
  • 12
  • 110
  • 164
  • The registry workaround seems to work, but the problem is that when the user clicks the (highlighted) dock button, it also changes the registry value, so next time, it would start undocked again. Any trick apart from modifying the registry value each time I need to show the on screen keyboard? Because for that the app would have to run elevated right? – Aros Dec 01 '20 at 10:29
  • 1
    @aros you don't have to be elevated to write to HKCU. – Anders Dec 01 '20 at 12:34
  • Oh really? Interesting. Will try that then. Thanks for the info. – Aros Dec 01 '20 at 12:45
  • Quite late, but yes, I can confirm that I was able to write to HKCU with no elevation. – Aros Aug 12 '21 at 15:38