function keyPressed() {
if (keyCode === "e") {
control *"system keyboard"* to output "e"
我想通过[可撕机器]用姿势打字(https://teachablemachine.withgoogle.com/train/pose)
最简单的解决方案是使用p5.jskey
属性,对于普通可打印键,该属性将是按下的键插入的字母的字符串(考虑移位键的状态(。只需确保将不可打印的键(Shift、Alt、Meta、Backspace、Tab、Enter、Escape等(考虑在内。
如果您不想使用内置的p5.js功能,那么这个问题是JavaScript中KeyCode的GetCharacter值的重复。。。然后修剪
我在评论中写了所有内容。。。
// copied this line of of the mozilla docs also this is for window rather than canvas
window.addEventListener("keydown", function(event){//you should just create a html canvas
// console.log(event.code) // and just select('#id')||('.class')||('canvas').
// console.log(event.code.replace("Key","")) // ya can also get rid of these console.log()-s
if(typeof getCharString === "function"){ // this checks if function exists
getCharString(event.code) // this'll give you the text
}
}) // idk if you can do this with p5.js or not tbh...
function getCharString(P_EN_GUI_N_AGHHHH){
console.log(`${P_EN_GUI_N_AGHHHH} !!!`)
console.log( P_EN_GUI_N_AGHHHH+"!!!")
}
// |
// here's just for copy |
// V
window.addEventListener("keydown", function(event){
if(typeof getCharString === "function"){
getCharString(event.code)
}
})
function getCharString(str){
console.log(str)
} // str == string