[DllImport(
"user32"
)] [/
float
][
float
=right][color=#4f4f4f][font="][size=16px]
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
(hideWindow)
{
startInfo.RedirectStandardOutput =
true
;
startInfo.RedirectStandardError =
true
;
startInfo.UseShellExecute =
false
;
startInfo.CreateNoWindow =
true
;
}
Process process =
new
Process();
process.StartInfo = startInfo;
process.Start();
return
process;
}