0
function keyPressed() {
  if (keyCode === "e") {
    control *"system keyboard"* to output "e" 

我想通过 [Teachable Machine.] ( https://teachablemachine.withgoogle.com/train/pose )输入带有姿势的字母

4

2 回答 2

1

最简单的解决方案是使用 p5.jskey属性,对于普通的可打印键,该属性将是被按下的键插入的字母的字符串(考虑到 shift 键的状态)。请确保您考虑了不可打印的键(Shift、Alt、Meta、Backspace、Tab、Enter、Escape 等)。

如果您不想使用内置的 p5.js 功能,那么这个问题与Get Character value from KeyCode in JavaScript 重复...然后修剪

于 2021-06-13T20:48:36.047 回答
0

我有点在评论中写了所有内容......

    // 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

于 2021-06-14T18:18:11.213 回答