1. 程式人生 > >U3D如何呼叫Win10的觸控鍵盤Touch KeyBoard非螢幕鍵盤(OSK.exe)

U3D如何呼叫Win10的觸控鍵盤Touch KeyBoard非螢幕鍵盤(OSK.exe)

最近一個專案要用到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;
}