Javascript/jquery Keyboard Event Introduction

Source: Internet
Author: User

First, need to know is:
1, KeyDown ()
The KeyDown event is triggered when the keyboard is pressed.
2, KeyUp ()
The KeyUp event is triggered when the key is released, which is the event you press the keyboard up
3, KeyPress ()
The KeyPress event is triggered when the button is tapped, and we can understand that pressing and lifting the same button

Second, obtain the corresponding ASCII code on the keyboard:

$ (document). KeyDown (function

$tips: In the example above, Event.keycode can help us to get to what button we pressed on the keyboard, he returned the ASCII code, such as the next key around, is 38,40,37,39;

Iii. instances (when pressing the left and right side keys on the keyboard)
The code is as follows:

$ (document). KeyDown (function(event) {//judge when Event.keycode is 37 o'clock (that is, left side key), execute function to_left ();//judge when Event.keycode is 39 o'clock (i.e. right-side key), execute function to_right (); if(Event.keycode = = 37) {to_left (); }Else if(Event.keycode = = 39) {to_right (); }         Else if(Event.keycode = = 38) {to_top (); }         Else if(Event.keycode = = 40) {to_bottom (); } }); functionTo_left () {$ (". ABC"). css ({' Left ': '-=10 ')});}functionTo_right () {$ (". ABC"). css ({' Left ': ' +=10 ')});}functionTo_top () {$ (". ABC"). css ({' Top ': '-=10 ')});}functionTo_bottom () {$ (". ABC"). css ({' Top ': ' +=10 '});}

Javascript/jquery Keyboard Event Introduction

Related Article

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.