进口代码,生产厂家→:On Screen Keyboard (PC and Console) best practices - Unity Answers

话不都说,直接上代码,复制粘贴到你的项目中

1、VirtualKeyboard.cs

using UnityEngine;
using System;
using System.Collections;
using System.Diagnostics;
using System.Runtime.InteropServices;public class VirtualKeyboard
{[DllImport("user32")]static extern IntPtr FindWindow(String sClassName, String sAppName);[DllImport("user32")]static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);private static Process _onScreenKeyboardProcess = null;/// <summary>/// Show the touch keyboard (tabtip.exe)./// </summary>public void ShowTouchKeyboard(){ExternalCall("C:\\Program Files\\Common Files\\Microsoft Shared\\ink\\tabtip.exe", null, false);//ExternalCall("TABTIP", null, false);}/// <summary>/// Hide the touch keyboard (tabtip.exe)./// </summary>public void HideTouchKeyboard(){uint WM_SYSCOMMAND = 274;int SC_CLOSE = 61536;IntPtr ptr = FindWindow("IPTip_Main_Window", null);PostMessage(ptr, WM_SYSCOMMAND, SC_CLOSE, 0);}/// <summary>/// Show the on screen keyboard (osk.exe)./// </summary>public void ShowOnScreenKeyboard(){//ExternalCall("C:\\Windows\\system32\\osk.exe", null, false);if (_onScreenKeyboardProcess == null || _onScreenKeyboardProcess.HasExited)_onScreenKeyboardProcess = ExternalCall("OSK", null, false);}/// <summary>/// Hide the on screen keyboard (osk.exe)./// </summary>public void HideOnScreenKeyboard(){if (_onScreenKeyboardProcess != null && !_onScreenKeyboardProcess.HasExited)_onScreenKeyboardProcess.Kill();}/// <summary>/// Set size and location of the OSK.exe keyboard, via registry changes. Messy, but only known method./// </summary>/// <param name='rect'>/// Rect./// </param>public void RepositionOnScreenKeyboard(Rect rect){ExternalCall("REG", @"ADD HKCU\Software\Microsoft\Osk /v WindowLeft /t REG_DWORD /d " + (int)rect.x + " /f", true);ExternalCall("REG", @"ADD HKCU\Software\Microsoft\Osk /v WindowTop /t REG_DWORD /d " + (int)rect.y + " /f", true);ExternalCall("REG", @"ADD HKCU\Software\Microsoft\Osk /v WindowWidth /t REG_DWORD /d " + (int)rect.width + " /f", true);ExternalCall("REG", @"ADD HKCU\Software\Microsoft\Osk /v WindowHeight /t REG_DWORD /d " + (int)rect.height + " /f", true);}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;}
}

2、OpenVirtualKeyboard.cs

public class OpenVirtualKeyboard
{static VirtualKeyboard vk = new VirtualKeyboard();//打开键盘public static void OpenKeyBoard(){vk.ShowTouchKeyboard();}//关闭键盘public static void CloseKeyBoard(){vk.HideTouchKeyboard();}}

3、完成功能:使用InputFiled,点击焦点时弹出,失去焦点时关闭

你需要将下面脚本挂到InputField上

InputFiledSelect .cs

using UnityEngine;
using UnityEngine.EventSystems;public class InputFiledSelect :  MonoBehaviour,ISelectHandler,IDeselectHandler
{public void OnDeselect(BaseEventData eventData){OpenVirtualKeyboard.CloseKeyBoard();}public void OnSelect(BaseEventData eventData){OpenVirtualKeyboard.OpenKeyBoard();}
}

如果运行成功,求个赞赞赞赞赞

Unity InputField输入框调用win10平板虚拟键盘相关推荐

  1. 自定义Unity在iOS平台上的虚拟键盘

    日本版本的玩家反馈,iOS的虚拟键盘无法点击确认按钮.观察了游戏内容如下: 发现确认按钮被长条的文本框给挤压了,不能完全显示. 于是观察了隔壁几家游戏是怎么处理虚拟键盘的,如图: 楚留香的键盘:明显重 ...

  2. U3D如何调用Win10的触摸键盘Touch KeyBoard非屏幕键盘(OSK.exe)

    最近一个项目要用到Windows的触摸键盘的功能,试过OSK屏幕键盘总感觉不怎么好用,试了下Win10自带的TabTip触摸键盘发现比较符合要求这里贴上U3D呼出和隐藏触摸键盘Touch KeyBoa ...

  3. Oculus Quest,Unity开发如何开启虚拟键盘

    最近在做一个VR虚拟会议,用到输入框,点击输入框的时候,需要开启虚拟键盘.我们主要使用了Oculus,集成了Oculus的SDK,也使用了MRTK作为我们开发3D界面的组件. 我是使用的Unity20 ...

  4. Qt-Arm交叉编译以及调用虚拟键盘(中英)

    环境:Qt5.15.1 交叉编译链:海思的板子,arm-himix200-linux- demo代码:Qt-Qml混合编程 第一步:环境搭建 1:从官网下载源码https://download.qt. ...

  5. html win10虚拟键盘,笔记本电脑win10虚拟键盘打开的方法

    win10是微软推出的新一代云操作系统,为用户提供多平台体验!如今,您可以在您的电脑中开启虚拟键盘,使用虚拟键盘轻松实现各种输入. 日常工作生活中,使用电脑时,有时需要开启虚拟键盘,包括"屏 ...

  6. Linux QT下实现简易虚拟键盘

    软件需要在仪器上面跑,故需要设计一个虚拟键盘来实现用户的输入. 实现思路比较简单,键盘上各个字母数字由一个个Btn组成,通过QT的信号槽机制来达到用户点击各个按钮来触发信号,从而实现模拟键盘点击.键盘 ...

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

    ShowTouchKeyboard():打开 键盘 HideTouchKeyboard():关闭键盘 这个方式打开有个坑:打开虚拟键盘后,没法直接切换输入法,必须先输入一个字母才可以切换. ----- ...

  8. android平板电脑的虚拟键盘,win10平板电脑不弹出虚拟键盘的两种解决方法

    平板电脑升级到了最新版Windows10系统后,发现在开机的时候没有弹出虚拟键盘,这样就没办法打字了,此问题对我们来说其实是比较少见的,如果真的出现这样的情况怎么办?今天小编就为大家整理了win10平 ...

  9. unity ugui android 小键盘,Unity inputfield 实现显示 隐藏密码功能(在安卓中切换不打开下虚拟键盘)...

    乍一看实现这个功能很简单,不就是切换一个inputfield的输入类型,将其换做password就可以了嘛. public void ToggleClick(bool isShow) { input. ...

最新文章

  1. 简谈WP,IOS,Android智能手机OS
  2. Linux 桌面的安装
  3. php视图,thinkPHP框架中视图的讲解(附代码)
  4. [系统安全] 六.逆向分析之条件语句和循环语句源码还原及流程控制
  5. http invoker_Http Invoker的Spring Remoting支持
  6. Java面试题目,java工程师成神之路
  7. android 混合开发 图片,混合开发的大趋势之一React Native之Image
  8. oc引导win方法_[OC更新]机械革命8代、9代标压稳定版更新
  9. uitextfield 键盘类型_以编程方式更改UITextField键盘类型
  10. A/B Problem
  11. IT巨头埃森哲遭 LockBit 勒索攻击,黑客威胁泄露数据
  12. make的时候会报错g++: Command not found
  13. 香港推广“绿色年宵” 呼吁商贩和市民惜物减废
  14. mysql-mmm+amoeba+keepalived实现mysql高可用和读写分离(二)
  15. 请简述一下RS485通讯连接方式及其应用?
  16. 【社会网络分析图】python实现
  17. Latex的常见错误
  18. API是什么意思,具体是什么?
  19. [论文]欠驱动水下机器人的平面轨迹规划与跟踪控制设计
  20. 猜数字游戏c语言提示范围,【游戏编程】猜数字游戏(C语言)

热门文章

  1. 齐岳钹形|UFO形|花生形|碗形Janus PS聚合物微球
  2. python 入门总结(一)
  3. [-Flutter趣玩篇-] 出神入化的Align+动画
  4. [Python] python 破解Excel密码(还原工作表密码)
  5. 【烈日炎炎战后端】消息队列(1.0万字)
  6. cisco 无线ap ME和LAP模式切换
  7. 收藏功能前端实现代码
  8. 羽素携手维琪共展科研实力,造护肤“芯”产链
  9. 使用C语言判断一个机器是大端机还是小端机
  10. 【博弈论】POJ[2348]Euclid's Game