-2

How can i make a function that when i press down for example "A" key on my keyboard it pushes down On and sends out signal for nupp('/TS'). Also on "A" key relase it should top sending the signal for nupp('/TS').

 <html>
  <head>
 <script src=\"https://code.jquery.com/jquery-2.2.4.min.js\"></script>
 <script>  client.println("function nupp(url){ $.ajax(url); }"</script>

 <button type=\"button\" onclick=\"nupp('/TS');\">On</button>


</head>
 <body>
in2d
  • 544
  • 9
  • 19

1 Answers1

1

You can do that like this:

function checkKeyDown(key) {
    if (key.keyCode == "38") {
        $.ajax("/F");
    } else if (key.keyCode == "37") {
        $.ajax("/L");
    } else if (key.keyCode == "39") {
        $.ajax("/R");
    } else if (key.keyCode == "40") {
        $.ajax("/B");
    }
}

function checkKeyUp(key) {
    if (key.keyCode == "38" || key.keyCode == "37" || key.keyCode == "39" || key.keyCode == "40") {
        $.ajax("/S");  //stop
    }
}
Paul
  • 4,160
  • 3
  • 30
  • 56
in2d
  • 544
  • 9
  • 19