title: Set numeric layout for windows onscreen keyboard programmatically
body: <p>Right now I'm trying to programmatically toogle the numeric layout for the Windows 8.1 onscreen keyboard also called "virtual keyboard" or "soft input panel (SIP)".</p>
  
  <p><a href="https://i.stack.imgur.com/rdotk.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rdotk.jpg" alt="numeric keyboard"></a></p>
  
  <p>It's not a WPF solution where I can set the InputScope, but I'm using a JavaFX application on a Windows 8.1 tablet. I know there is a built-in onscreen keyboard for JavaFX, but the metro style SIP (tabtip.exe) is called for.</p>
  
  <p>My current solution looks like this; I simulate a mouse click on the lower left corner of the keyboard where the "&amp;123" button is with C#. Compile this snippet into an .exe and call it from JavaFX e.g. when a TextField with numeric input receives focus. This has obvious downsides:</p>
  
  <p>1) It's hacky</p>
  
  <p>2) If the keyboard is in floating state and moved or some other screen-resolution is in place, the click coordinates might not be in the right spot.</p>
  
  <p>3) The app needs elevated privileges to spawn mouse events on the SIP</p>
  
  <p>What is a better way to do this? </p>
  
  <p>I've tried using Spy++ to analyse and found a "TipSkinEvent" when I press the "&amp;123" button.</p>
  
  <p>Based on <a href="https://stackoverflow.com/questions/1770670/how-do-i-control-the-text-input-panel-programmatically-tabtip-exe-in-windows-v"><img src="https://stackoverflow.com/questions/1770670/how-do-i-control-the-text-input-panel-programmatically-tabtip-exe-in-windows-v" alt="this post"></a> I came up with this:</p>
  
  <pre><code>void ToggleNum()
  {
      HWND hwndInputPanel = ::FindWindow(_TEXT("IPTip_Main_Window"), NULL);
  
      DWORD WM_NUM_BUTTON_PRESSED = ::RegisterWindowMessage(_TEXT("TipSkinEvent"));
      PostMessage(hwndInputPanel, WM_NUM_BUTTON_PRESSED, 0, 0);
  }
  </code></pre>
  
  <p>This doesn't work, and unfortunately I'm no expert in Windows programming thus I have no clue what has to be done here. Can you tell me what is wrong in the snippet or what the correct API is to change the layout as seen in the picture above? (Setting the numeric flag in the windows registry yields a different layout - and also needs admin rights to kill and restart tabtip.exe)</p>
  
  <p>To toggle the keyboard visibility I use a similar approach (calling C# code compiled into an .exe) This works fine (even without elevated privileges!). Based on <a href="https://stackoverflow.com/questions/38774139/show-touch-keyboard-tabtip-exe-in-windows-10-anniversary-edition/"><img src="https://stackoverflow.com/questions/38774139/show-touch-keyboard-tabtip-exe-in-windows-10-anniversary-edition/" alt="this post"></a></p>
  
  <p>A sidenote: I also tried to use JNA to skip the .exe call with no success.</p>