JS obtains the key value of the left and right mouse keys. js obtains the left and right keys.

Source: Internet
Author: User

JS obtains the key value of the left and right mouse keys. js obtains the left and right keys.

Function test () {alert (event. x + "" + event. y); alert (event. button);}/* The right-click menu does not display */document. oncontextmenu = function () {return false;}/* document. onmousedown = function () {if (event. button = 1) {alert ("left")} if (event. button = 2) {alert ("right")} */document. onkeydown = function () {alert (event. keyCode) ;}</script>

Event. x horizontal mouse axis
Event. y vertical axis of the mouse
Event. keycode keyboard Value
Events. button = 0 by default. No buttons are pressed.
Events. button = 1 left mouse button
Events. button = 2 right-click
Events. button = 3 press the mouse key at the same time
Events. button = 4 middle mouse buttons
Events. button = 5 press both the left mouse button and the middle mouse button
Events. button = 6 Right-click and press
Events. button = 7 all three keys are pressed


How to output the corresponding arrays of key values in JS one by one

Is your code JavaScript?

For key-value pairs, you can use for traversal, for example:
Var person = {name: 'zhangsan', age: 18 };
For (var p in person)
{
Alert (p + ":" + person [p]);
}

Q (js + html) How can I obtain the arrow keys of the keyboard to control the next image?

In js, the method can listen to buttons, and the left and right direction keys also have a key value. You can write a method to determine whether there are left and right keys, if yes, you can use these methods now! Onkeydown!

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.