8 why we required press down?


#1

I passed the code however, why we required press down there is no http://www.asciitable.com/ code to match my accuse code number is dec 031 as arrow down. the animate method does not make any sense to me.


#2

Hey Brian,

I'm not sure I understand what you're asking, could you try rephrasing your question please?

You're not being asked to press the down arrow, even though the word choice does kind of make it look like that. You can press any key you like, and the <div> will move 10 pixels to the right.


#3

The arrow keys are respectively,

Arrow      Key
 Key       Code

 left       37
  up        38
 right      39
 down       40

For the left hand we can use the letter keys, AWDS to perform the same function

   A        65
   W        87
   D        68
   S        83

keydown and keyup do not send charCode's so the shift key has no effect.

Let's apply this...

$(document).ready(function(){
    $(document).keydown(function(key){
        switch(parseInt(key.which, 10)){
        case 37:
        case 65:
            $('img').animate({left: '-=10px'}, 'fast');
            break;
        case 38:
        case 87:
            $('img').animate({top: '-=10px'}, 'fast');
            break;
        case 39:
        case 68:
            $('img').animate({left: '+=10px'}, 'fast');
            break;
        case 40:
        case 83:
            $('img').animate({top: '+=10px'}, 'fast');
            break;
        }
    });
});

#4

Aside:

Not to blow my own horn... I've written a small tool to help us identify the codes our keyboard sends to the KeyboardEvent Object:

KeyboardEvent Object

Click on the white part of the display and press any key. Only the data properties are listed, not the methods.


#5

this article is helpful when using the keycode chart is https://css-tricks.com/snippets/javascript/javascript-keycodes/
Why ascii table code different than keycode chart?

some ascii table is same as keycode chart.


#6

I can't give you a good answer, except to say that early keyboards did not send lowercase characters and there were only a limited number of special characters in the set, and it was confined to 7-bits, as I recall. Once keyboards and interfaces graduated to new generations, new encoding standards emerged to make sense of the rapid growth and global distribution of digital technology. Some of ASCII was preserved. By today's standards, ASCII is a blip in the rear-view mirror.


#7

@vanvlymenpaws They actually are the same. Look:

(CSS-Tricks)
——————————
| a | 65 |
——————————

(asciitable.com)
|Dec Hx Oct Html Chr|
—————————————————————
| 65 41 101 &#65; A |

(I'm guessing you're looking at the HTML column?)
When you press a key, it seems that JS gets the Decimal value of the character, even though the value could be shown in a couple other ways.

Did that clear anything up for you?


#8

all the char codes are fine. except the arrows. When using arrow control the case '37' of keycode chart, however I do not see ascii table said HTML column for the arrows control.

as long as using the keycode chart not ascii table.