JS get keyboard keycode-------Day42

Source: Internet
Author: User

Jinan today is pouring rain ah, this sultry swept away, but some thunder and lightning, the original want to complete today's blog record in the company, but do not know why do not log on the blog, it is estimated that the csdn then the server problem, fortunately to the evening, this thunder small also less, dare to continue to open the computer, Gossip doesn't say much, open up.

Most of the time I feel like a strange person, treat the same thing if interested, can be excited to do not know exhaustion, but if not interested, every moment is suffering, like said running, I always feel that long-distance running is a very painful thing, run a 400 to breathe a lot of time, can have friends invited me to shoot the basketball to run, even if not play, not to vote , so simple beat run, just like that silly run for a long time, the key is also feel very cool ....

About the JavaScript learning, I always feel can not be so monotonous to see the code, or to give themselves some fun, the game has become a point of order, can interact more can be fun, then for a computer, we can achieve the interactive means is limited can: keyboard, mouse, Of course, if there is a touch screen can be counted, and if you want to effective application, at least to know what you say, you tell it what the instructions, this requires us to understand its transmission principle and grammar more clearly, of course, we all know that the machine is reading the numbers, that is how to get it to the digital instructions it.

In this way, I first write to get the keyboard KeyCode method attached:

HTML language

<div style= "Width:500px;height:200px;background-color:cyan;" id= "Showzone" ></div>
JavaScript method:

Document.onkeydown=function (event) {var event=event| | Window.event;document.getelementbyid ("Showzone"). Innerhtml=event.keycode;};
so I can get a click on a button after the command, such as I pressed the "1", it shows "49", which is right.

First: To analyze this method, although it is already an old acquaintance, met many times, but there are a few points, but also today to figure out the point

Event:function (event) inside of the event, I tried to change the name, also tried to delete the directly, in IE really unaffected, so I believe those claims.

IE, there is an event built-in object, write it more because of compatibility;

The event can also be written here, the style of the event is just for easier understanding;

As for Var event=event| | Window.event, remember, before also specifically wrote an article, now go to see, Dog, but one thing is right, var event=event? event| | Window.event, it's a little easier to read.

Then, let's take a look at the corresponding keys for each of these buttons:




Have to say that the network is a good thing, these have been collated well, awesome, if we really want to have game operation, there are really so few need to pay attention to it, after all, the power of habit is huge

A:65, w:87, s:83, d:68, LEFT arrow: 37, clockwise rotation up, right, Next: 38,39,40, j:74

First of all, it is not listed, we still have to remember more.


I may not go fast, but I will let those who walk the road left the most beautiful traces, refueling ...


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.