function keyPressed() {
if (keyCode === "e") {
control *"system keyboard"* to output "e"
我想通过 [Teachable Machine.] ( https://teachablemachine.withgoogle.com/train/pose )输入带有姿势的字母
function keyPressed() {
if (keyCode === "e") {
control *"system keyboard"* to output "e"
我想通过 [Teachable Machine.] ( https://teachablemachine.withgoogle.com/train/pose )输入带有姿势的字母
最简单的解决方案是使用 p5.jskey
属性,对于普通的可打印键,该属性将是被按下的键插入的字母的字符串(考虑到 shift 键的状态)。请确保您考虑了不可打印的键(Shift、Alt、Meta、Backspace、Tab、Enter、Escape 等)。
如果您不想使用内置的 p5.js 功能,那么这个问题与Get Character value from KeyCode in JavaScript 重复...然后修剪
我有点在评论中写了所有内容......
// 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