JS gets the key value of the left and right mouse key method _javascript Tips

Source: Internet
Author: User
function test () 
{ 
alert (event.x+ "" +event.y); 
alert (Event.button); 
} 
/* Right-click menu does not show * 
/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 Mouse Axis
Event.y Mouse longitudinal axis
Event.keycode Keyboard Value
Events.button==0 default. No buttons were pressed.
Events.button==1 left mouse button
events.button==2 right mouse button
Events.button==3 the right mouse button and press
Events.button==4 The middle mouse button
Events.button==5 the left mouse button and the middle key pressed at the same time
Events.button==6 the right mouse button and the middle key at the same time
Events.button==7 all three keys are pressed

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.