Unity Touch keyboard on win10

https://answers.unity.com/questions/1134775/on-screen-keyboard-pc-and-console-best-practices.html

 

First you need to create VirtualKeyboard.cs script

  1. using UnityEngine;
  2. using System;
  3. using System.Collections;
  4. using System.Diagnostics;
  5. using System.Runtime.InteropServices;
  6. public class VirtualKeyboard
  7. {
  8. [DllImport("user32")]
  9. static extern IntPtr FindWindow(String sClassName, String sAppName);
  10. [DllImport("user32")]
  11. static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
  12. private static Process _onScreenKeyboardProcess = null;
  13. /// <summary>
  14. /// Show the touch keyboard (tabtip.exe).
  15. /// </summary>
  16. public void ShowTouchKeyboard()
  17. {
  18. ExternalCall("C:\\Program Files\\Common Files\\Microsoft Shared\\ink\\tabtip.exe", null, false);
  19. //ExternalCall("TABTIP", null, false);
  20. }
  21. /// <summary>
  22. /// Hide the touch keyboard (tabtip.exe).
  23. /// </summary>
  24. public void HideTouchKeyboard()
  25. {
  26. uint WM_SYSCOMMAND = 274;
  27. int SC_CLOSE = 61536;
  28. IntPtr ptr = FindWindow("IPTip_Main_Window", null);
  29. PostMessage(ptr, WM_SYSCOMMAND, SC_CLOSE, 0);
  30. }
  31. /// <summary>
  32. /// Show the on screen keyboard (osk.exe).
  33. /// </summary>
  34. public void ShowOnScreenKeyboard()
  35. {
  36. //ExternalCall("C:\\Windows\\system32\\osk.exe", null, false);
  37. if (_onScreenKeyboardProcess == null || _onScreenKeyboardProcess.HasExited)
  38. _onScreenKeyboardProcess = ExternalCall("OSK", null, false);
  39. }
  40. /// <summary>
  41. /// Hide the on screen keyboard (osk.exe).
  42. /// </summary>
  43. public void HideOnScreenKeyboard()
  44. {
  45. if (_onScreenKeyboardProcess != null && !_onScreenKeyboardProcess.HasExited)
  46. _onScreenKeyboardProcess.Kill();
  47. }
  48. /// <summary>
  49. /// Set size and location of the OSK.exe keyboard, via registry changes. Messy, but only known method.
  50. /// </summary>
  51. /// <param name='rect'>
  52. /// Rect.
  53. /// </param>
  54. public void RepositionOnScreenKeyboard(Rect rect)
  55. {
  56. ExternalCall("REG", @"ADD HKCU\Software\Microsoft\Osk /v WindowLeft /t REG_DWORD /d " + (int)rect.x + " /f", true);
  57. ExternalCall("REG", @"ADD HKCU\Software\Microsoft\Osk /v WindowTop /t REG_DWORD /d " + (int)rect.y + " /f", true);
  58. ExternalCall("REG", @"ADD HKCU\Software\Microsoft\Osk /v WindowWidth /t REG_DWORD /d " + (int)rect.width + " /f", true);
  59. ExternalCall("REG", @"ADD HKCU\Software\Microsoft\Osk /v WindowHeight /t REG_DWORD /d " + (int)rect.height + " /f", true);
  60. }
  61. private static Process ExternalCall(string filename, string arguments, bool hideWindow)
  62. {
  63. ProcessStartInfo startInfo = new ProcessStartInfo();
  64. startInfo.FileName = filename;
  65. startInfo.Arguments = arguments;
  66. // if just command, we don't want to see the console displayed
  67. if (hideWindow)
  68. {
  69. startInfo.RedirectStandardOutput = true;
  70. startInfo.RedirectStandardError = true;
  71. startInfo.UseShellExecute = false;
  72. startInfo.CreateNoWindow = true;
  73. }
  74. Process process = new Process();
  75. process.StartInfo = startInfo;
  76. process.Start();
  77. return process;
  78. }
  79. }

then call from your script like below

  1. VirtualKeyboard vk = new VirtualKeyboard();
  2. public void OpenKeyboard()
  3. {
  4. {
  5. vk.ShowTouchKeyboard();
  6. }
  7. }
  8. public void CloseKeyboard()
  9. {
  10. {
  11. vk.HideTouchKeyboard();
  12. }
  13. }

 

 

Resizing

http://forum.tabletpcreview.com/threads/how-to-resize-on-screen-keyboard.70030/

 

The gigantic On-Screen keyboard covers up half of the screen
and program window on my Surface Pro 3. using Windows 8.1
I have been using the M.S. Accessibility keyboard as you can resize it, but it
has the huge sidebars, etc. and you can not write out text input.

A friend showed me a Registry hack that resizes the OnScreen Keyboard.
(As always, back up your registry, use at your own risk)

1) Go to RUN–
Type :
regedit

2) Browse to:
HKLM(Local Machine)>Software>Microsoft>Windows>CurrentVersion>Explorer

3) Once at Explorer> Rt Click on Explorer folder and Add New Key
Type:
Scaling
(This adds a new folder titled ‘Scaling’ under Explorer)

4) Rt Click on Scaling folder:
Add– New String Value
Type:
Monitorsize

5) Double Click on MoniterSize:
Enter String Value “25”
(For a half screen-width keyboard)

6) Restart or Shut down/Restart
Keyboard will now pop up much smaller

Smaller numbers results in larger keyboard.
20=2/3 screen width
Experiment for your desired size.

So far I have not experienced any abnormalities, in other programs
I use Internet Explorer for web browsing.

I understand it also works in Windows 10,
but I don’t have Windows 10 to test it.

Leave a Reply

Your email address will not be published. Required fields are marked *