100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > Unity 调用系统自带的虚拟键盘

Unity 调用系统自带的虚拟键盘

时间:2022-07-06 15:18:51

相关推荐

Unity 调用系统自带的虚拟键盘

说明

两种方式启动了Win10自带的两种虚拟键盘。

tabtip.exe 在有些系统上启动不了(不知道为啥,所以才有了第二种)

代码

using System;using System.Diagnostics;using System.Runtime.InteropServices;using UnityEngine;public class TouchKeyboard{static Process sf;[DllImport("user32")]static extern IntPtr FindWindow(String sClassName, String sAppName);[DllImport("user32")]static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);static string path = "C:\\Program Files\\Common Files\\Microsoft Shared\\ink\\tabtip.exe";/// <summary>/// 显示屏幕键盘/// </summary>public static void ShowTouchKeyboard(){try{ExternalCall(path, null, false);}catch (Exception e){UnityEngine.Debug.Log(e);}}/// <summary>/// 隐藏屏幕键盘/// </summary>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 displayedif (hideWindow){startInfo.RedirectStandardOutput = true;startInfo.RedirectStandardError = true;startInfo.UseShellExecute = false;startInfo.CreateNoWindow = true;}Process process = new Process();process.StartInfo = startInfo;process.Start();return process;}public static void Open(){sf = System.Diagnostics.Process.Start(@"C:\Windows\System32\osk.exe");}public static void Close(){if(sf != null){sf.Kill();sf = null;}}}

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