0
votes

I can control my bot through web. These are its url-

I am using html button to do this. But I want to control it with "arrow" key of keyboard. My idea is if I press and hold up arrow key then the bot will go forward(https://172.0.0.1/forward) and if I release the up arrow key then the bot will Stop(https://172.0.0.1/stop) going. and the same thing to

  • backward - "down arrow"
  • left- "left arrow"
  • right-"right arrow"

I'm not familiar with JavaScript Can you please help me...

1
You should call your function "onkeydown" event, and stop the function when "onkeyup" triggers. - Yah Ya
Hi, welcome on SO. Before asking questions here, you should try by yourself to find a solution, ask the internet, Google, or whatever, and then show here your research effort and tell why it did not work. For example, you could start by googling something like: "javascript action on key down". - dgiugg

1 Answers

1
votes

try like this.

window.addEventListener('keydown',function(event){
if(event.keyCode===37) { //left
}
if(event.keyCode===38) { //up
}

if(event.keyCode===39) { //right
}
if(event.keyCode===40) { //down
}

});

UPDATE

window.addEventListener('keyup',function(event){
//    do something

});