我正在构建一个使用 keyPressed 在屏幕上写字的应用程序。这在 PC 上效果很好,但在移动设备上我不知道如何调出虚拟键盘。我环顾四周,没有找到任何特定于 p5js 的解决方案......而且我一般并不真正精通 javascript/web 编程。 GPT 说我应该添加一个输入元素并将其隐藏:
var hiddenInput
function setup() {
createCanvas(windowWidth, windowHeight);
background(200);
hiddenInput = createInput('');
hiddenInput.style('display', 'none'); // Hide the input element
hiddenInput.position(0, 0);
hiddenInput.size(windowWidth, windowHeight);
hiddenInput.input(updateWords);
}
...
function touchStarted() {
// Focus on the input element when the canvas is touched
hiddenInput.elt.focus();
}
但是我无法让键盘显示出来。
有人可以帮我吗?
谢谢!