ShowTouchKeyboard();打开 键盘
HideTouchKeyboard();关闭键盘
这个方式打开有个坑:打开虚拟键盘后,没法直接切换输入法,必须先输入一个字母才可以切换。
----------------------------分割线-------------------------
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
///
/// 虚拟键盘管理类
///
public class JianPanCtl
{
[DllImport(“user32”)]
static extern IntPtr FindWindow(String sClassName, String sAppName);
[DllImport(“user32”)]
static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
///
/// 显示屏幕键盘
///
public static void ShowTouchKeyboard()
{
try
{
ExternalCall(“C:\Program Files\Common Files\Microsoft Shared\ink\tabtip.exe”, null, false);
}
catch (Exception e)
{
UnityEngine.Debug.Log(e);
}
}
///
/// 隐藏屏幕键盘
///
public static 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();
process.Refresh();
return process;
}
}
---------------------------分割线-------------------------