Unity 中的键盘输入Keyboard input in Unity

03/30/2021

本文内容

命名空间: UnityEngineNamespace: UnityEngine

虽然 HoloLens 支持多种形式的输入,包括蓝牙键盘,但大多数应用程序都无法假定所有用户都有可用的物理键盘。While HoloLens supports many forms of input including Bluetooth keyboards, most applications can't assume that all users will have a physical keyboard available. 如果你的应用程序需要文本输入,则应该提供某种形式的屏幕键盘。If your application requires text input, some form of on-screen keyboard should be provided.

Unity 提供了Unity provides the

Unity 中的 HoloLens 系统键盘行为HoloLens system keyboard behavior in Unity

在 HoloLens 上, TouchScreenKeyboard 利用系统的屏幕键盘,并直接覆盖 MR 应用程序的容量耗尽视图。On HoloLens, the TouchScreenKeyboard leverages the system's on-screen keyboard and directly overlays on top of the volumetric view of your MR application. 经验类似于在 HoloLens 内置应用程序中使用键盘。The experience is similar to using keyboard in the built-in apps of HoloLens. 请注意,系统键盘的行为取决于目标平台的功能,例如,HoloLens 2 上的键盘支持直接交互,而 HoloLens 上的键盘 (第一代) 将支持 GGV (注视、手势和语音) 。Note that the system keyboard will behave according to the target platform's capabilities, for example the keyboard on HoloLens 2 would support direct hand interactions, while the keyboard on HoloLens (1st gen) would support GGV (Gaze, Gesture, and Voice). 此外,在从编辑器向 HoloLens 执行 Unity 远程处理时,系统键盘不会显示。Additionally, the system keyboard will not show up when performing Unity Remoting from the editor to a HoloLens.

在 Unity 应用中使用系统键盘Using the system keyboard in your Unity app

声明键盘Declare the keyboard

在类中,声明一个用于存储 TouchScreenKeyboard 的变量,并声明一个用于保存键盘返回的字符串的变量。In the class, declare a variable to store the TouchScreenKeyboard and a variable to hold the string the keyboard returns.

UnityEngine.TouchScreenKeyboard keyboard;

public static string keyboardText = "";

调用键盘Invoke the keyboard

当请求键盘输入的事件发生时,使用以下项显示键盘。When an event occurs requesting keyboard input, use the following to show the keyboard.

keyboard = TouchScreenKeyboard.Open("text to edit");

您可以使用传递到函数的其他参数 TouchScreenKeyboard.Open 来控制键盘的行为 (例如,设置占位符文本或支持自动更正) 。You can use additional parameters passed into the TouchScreenKeyboard.Open function to control the behavior of the keyboard (e.g. setting placeholder text or supporting autocorrection). 有关参数的完整列表,请参阅 Unity 的文档。For the full list of parameters please refer to Unity's documentation.

检索类型化内容Retrieve typed contents

只需调用即可检索内容 keyboard.text 。The content can simply be retrieved by calling keyboard.text. 您可能想要每帧检索内容,或仅在键盘关闭时检索内容。You may want to retrieve the content per frame or only when the keyboard is closed.

keyboardText = keyboard.text;

备用键盘选项Alternative keyboard options

除了直接使用 TouchScreenKeyboard 类之外,还可以使用 Unity 的 UI 输入字段 或 TextMeshPro 输入字段 获取用户输入。Besides using the TouchScreenKeyboard class directly, you can also get user input by using Unity's UI Input Field or TextMeshPro Input Field. 此外,在 MRTK的 HandInteractionExamples 场景中有一个基于 TouchScreenKeyboard 的实现 () 左侧有一个键盘交互示例。Additionally, there is an implementation based on TouchScreenKeyboard in the HandInteractionExamples scene of MRTK (there is a keyboard interaction sample on the left hand side).

下一个开发检查点Next Development Checkpoint

如果遵循我们所说的 Unity 开发旅程,就是探索混合现实平台功能和 Api。If you're following the Unity development journey we've laid out, you're in the midst of exploring the Mixed Reality platform capabilities and APIs. 在这里,你可以继续阅读任何 主题 ,也可以直接跳转到在设备或模拟器上部署你的应用程序。From here, you can continue to any topic or jump directly to deploying your app on a device or emulator.

u3d计算机获取键盘输入,Unity 中的键盘输入相关推荐

  1. Unity中打开键盘+平板打开键盘+windows打开默认小键盘

    目录 一.目的 1.想知道:Unity中打开键盘+平板打开键盘+windows打开默认小键盘 二.参考 1.Unity之修改UGUI中InputFiled输入框调用的键盘类型 1.System.Inv ...

  2. java获取键盘整数_Java中从键盘输入多个整数的方法

    例题:求数列的和 分别输入两个整数n,m,中间以空格隔断,n 为数列第一项,后面各项均为前一项的开根号,求前m项的和. 第一种从键盘输入并读取的方式:sc.hasNextInt() 函数和sc.nex ...

  3. 在java中通过过键盘输入_java中从键盘输入

    控制台输入数据 1.1 主方法的形式参数 在 Java 中利用 main(Str... Java中获取键盘输入值的三种方法 2012-11-13 00:00比特网悠虎关键字:Java 程序开发过程中, ...

  4. java怎么设置多个输入_Java中从键盘输入多个整数的方法

    Java中从键盘输入多个整数的方法 发布于 2020-4-2| 复制链接 分享一篇关于Java中从键盘输入多个整数的方法,具有很好的参考价值,希望对大家有所帮助.一起跟随小妖过来看看吧 例题:求数列的 ...

  5. python获取键盘按键_Python中捕获键盘的方式详解

    python中捕获键盘操作一共有两种方法 第一种方法: 使用pygame中event方法 使用方式如下:使用键盘右键为例 if event.type = pygame.KEYDOWN and even ...

  6. 安卓如何调出软键盘_Android开发中软键盘的显示和隐藏

    本篇内容通过操作软键盘的函数着手详细分析了隐藏或者显示软键盘的实现方法,并且对其中重要的代码做了详细分析. 一.开篇 如果有需要用到输入的地方,通常会有需要自动弹出或者收起软键盘的需求.开篇明义,本文 ...

  7. python编程midi键盘按键_Python中捕获键盘的方式详解

    python中捕获键盘操作一共有两种方法 第一种方法: 使用pygame中event方法 使用方式如下:使用键盘右键为例 if event.type = pygame.KEYDOWN and even ...

  8. java 获取键盘输入法_Java中接收键盘输入的三种方法

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import ...

  9. 安卓应用SHA1的获取并在Unity中打包发布

    项目背景 项目中需要使用SHA1申请一个SDK的APPKey,在此记录一下SHA1相关知识. SHA1介绍 SHA-1(英语:Secure Hash Algorithm 1,中文名:安全散列算法1)是 ...

  10. Unity中模拟键盘按键(转)

    做手机游戏时需要通过UI上的按钮控制物体,原来的脚本用于电脑端上运行,通过键盘按下按键,Input.GetAxisRaw("Vertical")和"Horizontal& ...

最新文章

  1. 2744 养鱼喂妹纸
  2. 外链对网站SEO优化起什么作用?
  3. HDOJ1035 ( Robot Motion ) 【递归】
  4. SLAM学习--视觉slam学习教材推荐(附相关技术文档下载链接)
  5. jieba分词错误_如何掌握分词技术,你需要学会这些
  6. Java的四种引用,强弱软虚,用到的场景(转+补充)
  7. echart 高度 不用 不撑满_你担心的高度近视老了之后是这样的
  8. 清华大学829电磁场考研资料
  9. 【JDK】Mac版安装JDK并配置环境
  10. 【BCM】博通 linux-4.19 gcc-9.2 toolchain 环境搭建
  11. 【EXLIBRIS】墙上的坏人
  12. element-ul基本使用
  13. 网站漏洞如何修复web漏洞jeecms
  14. android屏幕坏 操作手机,手机屏幕碎了怎么备份操作?
  15. 3.矩阵乘法和逆矩阵
  16. 透析阿里3亿元投资的如涵:孵化张大奕,吸金但苦逼
  17. 鼎力测试软件安不上,e5 2665 安装成功,但是不能睿频
  18. python or的用法_详细介绍Python中and和or实际用法
  19. 音速索尼克 怪人_科学怪人,半死僵尸和其他怪物
  20. 樱陀花园10月份活动策划

热门文章

  1. 口袋妖怪lets go服务器维护中,口袋妖怪lets go攻略 口袋妖怪lets go新手攻略(中)...
  2. Adobe flash player ActiveX、NPAPI、PPAPI 的区别
  3. why-not 和 why 问题简介
  4. 程序员确实更容易秃....
  5. java.sql.SQLException: No database selected
  6. 【人脸表情识别】基于matlab GUI微表情识别系统【含Matlab源码 1852期】
  7. LeetCode——5805. 最小未被占据椅子的编号(The Number of the Smallest Unoccupied Chair)[中等]——分析及代码(Java)
  8. 导出 excel表格(数据、echarts图片)
  9. Python—Scrapy爬取京东商城
  10. linux下mp3编码库libmp3lame的开发使用