Html 输入数字未获取数字键盘输入

Html input number is not getting numeric keyboard input

这里是input类型number

<input type="Number" id="yPos" />

它工作正常,我可以通过鼠标更改它

但是它没有从键盘获取数字输入。我怎样才能启用它?

编辑: 我发现 UnitywebGL 造成了这个问题,否则键盘输入在 html 控件中工作正常。

首先,更正表格。类型应该是 "number" 没有大写,即:

type="number"

同时检查您是否关闭了数字锁定。

实际上 html 输入字段没有问题。跟unity webgl有关:

Keyboard input and focus handling. By default, Unity WebGL will process all keyboard input send to the page, regardless of whether the WebGL canvas has focus or not. This is done so that a user can start playing a keyboard-based game right away without the need to click on the canvas to focus it first (source).

所以 Unity canvas 占用了我所有的键盘输入。无论我尝试 enter/select 我的输入控件,它都不会从键盘获得输入。所以我用了

WebGLInput.captureAllKeyboardInput 

至activate/deactive统一canvas输入基于用户选择。