在画布上,当我按下箭头键或与此相关的任何键时,不会触发keyPressed事件(控制台不会记录“按下键”消息)。下面是我的代码:
<!doctype html>
<html>
<head>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.0/p5.js"></script>
</script>
</head>
<body>
<div id="game-wrapper">
<div id="canvas-wrapper">
</div>
</div>
</div>
<script>
myp25 = new p5(mazeDisplay, "canvas-wrapper");
var mazeDisplay = function (p) {
p.setup = function () {
var canvas = p.createCanvas(705, 465);
p.background(0, 0, 0);
}
p.keyPressed = function() {
console.log("key pressed!");
}
};
</script>
</body>
</html>