100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > Unity开发win10软件系列问题6: unity调用 win10 虚拟键盘tabtip.exe

Unity开发win10软件系列问题6: unity调用 win10 虚拟键盘tabtip.exe

时间:2023-01-01 21:48:44

相关推荐

Unity开发win10软件系列问题6: unity调用 win10 虚拟键盘tabtip.exe

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;

}

}

---------------------------分割线-------------------------

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。