If no matter what key is pressed then try this:
PHP Code:
var delay=100; //delay time in milliseconds
var left=0; //Initial X position
var right=window.width/2; // Final X position
var top=window.height/2; //Initial Y position
var bottom=windows.height; //Final Y position
var Xstep=windows.width/60; //X moving step
var Ystep=windows.height/10; //Y moving step
function MovingObject(ObjectToMove) {
ObjectToMove.scrLeft=left;
ObjectToMove.scrTop=top;
setTimeOut(delay,"Moving(ObjectToMove)");
}
function Moving(ObjectToMove) {
if(ObjectToMove.scrLeft<=right) {
ObjectToMove.srcLeft=ObjectToMove.srcLeft + Xstep;
setTimeOut(delay,"Moving(ObjectToMove)");
} else {
if(ObjectToMove.scrTop<=bottom) {
ObjectToMove.scrTop=ObjectToMove.scrTop+Ystep;
setTimeOut(delay,"Moving(ObjectToMove)");
}
}
}
document.keydown=MovingObject(xyz); //xyz is the object you wanna move
If have to be a specific key to activate the motion, modify this:
PHP Code:
function MovingObject(ObjectToMove) {
if(document.event.KeyCode == 13) { //This makes the ENTER key activate the motion
ObjectToMove.scrLeft=left;
ObjectToMove.scrTop=top;
setTimeOut(delay,"Moving(ObjectToMove)");
}
}
For other keys you have to figure out the KeyCode.
I can do this way:
PHP Code:
<HTML><HEAD><SCRIPT language="JavaScript"><!--
function GetKeyCode() {
alert("KeyCode is " + document.event.KeyCode);
}
document.keydown=GetKeyCode();
}
--></SCRIPT></HEAD>
<BODY>
<P> Press the key you want to know the KeyCode
</BODY></HTML>
I hope it be usefull