最近一个项目要用到Windows的触摸键盘的功能,试过OSK屏幕键盘总感觉不怎么好用,试了下Win10自带的TabTip触摸键盘发现比较符合要求这里贴上U3D呼出和隐藏触摸键盘Touch KeyBoard也就是TabTip.exe的方法,win8理论上也可以用
[DllImport("user32")]
static extern IntPtr FindWindow(String sClassName, String sAppName);
[DllImport("user32")]
static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
/// <summary>
/// 显示屏幕键盘
/// </summary>
public void ShowTouchKeyboard()
{
try
{
ExternalCall("C:\\Program Files\\Common Files\\Microsoft Shared\\ink\\tabtip.exe", null, false);
}
catch (Exception e)
{
UnityEngine.Debug.Log(e);
}
}
/// <summary>
/// 隐藏屏幕键盘
/// </summary>
public void HideTouchKeyboard()
{
try
{
uint WM_SYSCOMMAND = 274;
int SC_CLOSE = 61536;
IntPtr ptr = FindWindow("IPTip_Main_Window", null);
PostMessage(ptr, WM_SYSCOMMAND, SC_CLOSE, 0);
}
catch (Exception e)
{
UnityEngine.Debug.Log(e);
}
}
private static Process ExternalCall(string filename, string arguments, bool hideWindow)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = filename;
startInfo.Arguments = arguments;
// if just command, we don't want to see the console displayed
if (hideWindow)
{
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
}
Process process = new Process();
process.StartInfo = startInfo;
process.Start();
return process;
}