title: How to make the Windows OSK open when a TextBox gets focus, instead of requiring users to tap a keyboard icon?
body: <p>We are working on a WPF application in .NET 4 that will be used with a touch screen.  We are trying to use the built-in Windows OSK for our input, and the last remaining issue is to get the keyboard to open up as soon as a text box gets focus.  Currently, if a text box gets focus, a small keyboard icon appears (this is the InputPanel icon) and the user has to tap that icon to make the keyboard open up.</p>
  
  <p>Is there a way to skip the icon step, and just have the keyboard open up all the way on focus?  Preferably something that can be set or coded in one place and apply to all text boxes globally?  It also needs to use the current culture settings of the application thread (which it already appears to be doing).</p>
  
  <p>I haven't been able to find anything in the control panel settings that lets you skip the icon step.  I also found some examples online of using the <a href="http://msdn.microsoft.com/en-us/library/microsoft.ink.textinput.textinputpanel.currentinplacestate%28v=VS.85%29.aspx" rel="nofollow">TextInputPanel.CurrentInPlaceState</a>, but when I implemented code to open up a TextInputPanel on preview focus of the main window, I kept getting COM INTEROP exceptions and basically hit a dead end (the Microsoft.Ink.dll is an interop DLL).</p>
  
  <p>Is it possible that there is a registry key that can change the default CurrentInPlaceState to Expanded instead of HoverTarget?  I haven't been able to find one in my net searching.</p>
  
  <p>Thanks,</p>
  
  <p>Valerie</p>
  
  <p><strong>EDIT</strong>:  Here is some code that I put in the main window's code behind, as well as the exception message I keep getting - and I have no idea what it means or how to fix it (my net searches failed me!)</p>
  
  <pre><code>protected override void OnPreviewGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
      {
          base.OnPreviewGotKeyboardFocus(e);
  
          TextBox textbox = e.NewFocus as TextBox;
          TextBox oldTextbox = e.OldFocus as TextBox;
  
          if (oldTextbox != null &amp;&amp; boxesToInputs.ContainsKey(oldTextbox))
          {
              TextInputPanel oldPanel = boxesToInputs[oldTextbox];
              oldPanel.Dispose();
              boxesToInputs.Remove(oldTextbox);
          }
  
          if (textbox != null)
          {
              // Make sure we've cleaned up old panels, just in case
              if (boxesToInputs.ContainsKey(textbox))
              {
                  boxesToInputs[textbox].Dispose();
                  boxesToInputs.Remove(textbox);
              }
  
              TextInputPanel newPanel = new TextInputPanel(((HwndSource)PresentationSource.FromDependencyObject(textbox)).Handle);
              newPanel.DefaultInPlaceState = InPlaceState.Expanded;
              newPanel.DefaultInputArea = PanelInputArea.Keyboard;
              boxesToInputs[textbox] = newPanel;
          }
      }
  </code></pre>
  
  <p>And here is the exception message, which occurs when my code calls the TextInputPanel constructor:</p>
  
  <blockquote>
    <p>Retrieving the COM class factory for component with CLSID {F9B189D7-228B-4F2B-8650-B97F59E02C8C} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))</p>
  </blockquote>
  
  <p>I verified that the platform target of the WPF app is x86.  I ran Dependency Walker and it said that the Microsoft.Ink.dll I was using was 64 bit, and that two delay-loaded dependencies were missing (GPSVC.dll and IESHIMS.dll).  I found a 32 bit version of Microsoft.Ink.dll, but I am still getting the same error, and Dependency Walker is saying the same thing - GPSVC.dll and IESHIMS.dll are missing.</p>
  
  <p>I can't target x64, and I'd prefer not to have to put the missing DLLs into my application folder (if that would work?).  I hope there is something simple I am missing, because this is a lot of trouble to just get rid of a keyboard hint...</p>
  
  <p>Any help is greatly appreciated - I am a bit of a newb when it comes to working with unmanaged/interop assemblies...</p>