Results 1 to 2 of 2

Thread: usings arrowkeys

  1. #1

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    usings arrowkeys

    Hi
    using arrow keys how can I make my image or an object MOVE DOWNWARD THEN LEFTWARD...
    ***********
    MY second question is that " pressing a button let my image or object MOVE RIGHT for 3 or 5 seconds and then let it MOVE DOWNWARD...

  2. #2
    Junior Member
    Join Date
    Aug 2002
    Location
    Brazil
    Posts
    29
    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>
    <
    PPress the key you want to know the KeyCode
    </BODY></HTML
    I hope it be usefull

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width