I want to move the board I create using left arrow to move left and right arrow to move right. But I don’t know how to write left / right arrow in syntax, so I just use ‘a’ and ‘d’ to move left and right (like in counter strike).
Could anyone help me?
Here is my code
function moveObj(name, Xpix)
{
obj = document.getElementById(name);
px = parseInt(obj.style.left) + Xpix;
obj.style.left = px;
}
function ProcessKeypress(e)
{
var myObj = "pantul";
var moveBy = 10;
obj = document.getElementById(myObj);
x=parseInt(obj.style.left);
if (e.keyCode) keycode=e.keyCode;
else keycode=e.which;
ch=String.fromCharCode(keycode);
if(x > 220 || x <720)
{
if(ch=='a') moveObj(myObj, -moveBy);
else if(ch=='d') moveObj(myObj, moveBy);
}
}
so you can use keycode(not char),