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

Source: Internet
Author: User

Jinan today is pouring rain ah, this sultry swept away, just some thunder and lightning, the original wanted in the company on the end of today's blog record, just do not know why do not log on blog, is expected to be csdn at that time the server problem, fortunately to the evening, this thunder small also less, dare to continue to open the computer , gossip not much to say, open to engage.

Very often I think oneself is a strange person, treat the same thing assumption interested, can be excited to do not know exhaustion, can assume is not interested, every moment is suffering, like say running, I always feel long-distance running is a very painful thing, run a 400 all want to catch a lot of time, can have a friend invited me to shoot the basketball to run, , do not cast, so simple beat run, just like that silly run for a long time, the key is also feel cool pole ....

About the JavaScript learning, I always feel can not be so monotonous to see the code, or to give yourself some fun, the game has become a start point, can interact more can be a pleasure, then for a computer, we can achieve the interactive means is limited to: keyboard, mouse, Of course, if there is a touch screen can be counted, and the false idea to effective application, at least to know what you say, what you tell it, this requires us to understand its transmission principle and grammar more clearly, of course, we all know that the machine is reading the numbers, then 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, for example, 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 a lot of other is due to compatibility;

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

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

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




Have to say that the network is a good thing, these have been collated well, awesome, we assume that there is really a 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.