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

I want to type letters with poses via the [Teachable Machine.] (https://teachablemachine.withgoogle.com/train/pose)

Carl Kho
  • 1
  • 1

2 Answers2

1

The simplest solution would be to use the p5.js key property, which for normal printable keys will be the string for the letter inserted by the key being pressed (taking the state of the shift key into account). Just be sure you take the non-printable keys (Shift, Alt, Meta, Backspace, Tab, Enter, Escape, etc.) into account.

If you don't want to use the built in p5.js capabilities, then this question is a duplicate of Get Character value from KeyCode in JavaScript... then trim

Paul Wheeler
  • 18,988
  • 3
  • 28
  • 41
0

I kinda wrote everything within comments...

    // 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
Ulti
  • 514
  • 3
  • 5