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;
}
}

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值