我在RPi上的javascript程序出现问题

时间:2014-06-09 14:33:26

标签: javascript

我是javascript的新手并制作了一个程序来控制我的RPi机器人而不是Wlan ......但是我遇到了一个问题。每次当我持有W,A或D较长时间时,机器人会发疯并且不想停在一个方向上行驶,直到我按下另外两个按键之一。我可以通过Web界面控制机器人。这是代码:

<html>
<head>
<script Language="Javascript">

window.addEventListener("keydown", onKeyDown, false);
window.addEventListener("keyup", onKeyUp, false);
function set0()
{
document.location="cgi-bin/set0.cgi";
}
function set1()
{
document.location="cgi-bin/set1.cgi";
}
function set01()
{
document.location="cgi-bin/set01.cgi";
}
function clear01(event)
{
document.location="cgi-bin/clear01.cgi";
}

function onKeyDown(event){
var keyCode = event.keyCode;
switch(keyCode){
case 87:  //w
    set01();
break;
case 68:  //d
    set1();
break;
case 65:  //a
    set0();
break;
}
}
function onKeyUp(event){
var keyCode = event.keyCode;
switch(keyCode){
case 87:  //w
    clear01(event);
break;
case 68:  //d
    clear01(event);
break;
case 65: //a
    clear01(event);
break;
}
}

</script>
</head>
<body>
<div style="text-align:center">
<h1>The PiRover</h1>

<img src="/forward.jpg" id="f" onmousedown="set01()" onmouseup="clear01(event)">
<br>
<img src="/left.jpg" id="l" onmousedown="set0()" onmouseup="clear01(event)">
<img src="/right.jpg" id="r" onmousedown="set1()" onmouseup="clear01(event)">
<br>
<img src="/stop.jpg" id="s" onmousedown="clear01(event)" onmouseup="clear01(event)">
</div>

</body>
</html>

0 个答案:

没有答案