Home >Web Front-end >JS Tutorial >JS method to obtain the key values ​​of the left and right mouse buttons_javascript skills

JS method to obtain the key values ​​of the left and right mouse buttons_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:34:211676browse
function test() 
{ 
alert(event.x+" "+event.y); 
alert(event.button); 
} 
/*右键菜单不显示*/ 
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 horizontal axis
event.y mouse vertical 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 Press the left and right mouse buttons simultaneously
events.button==4 middle mouse button
events.button==5 The left and middle mouse buttons are pressed simultaneously
events.button==6 The right and middle mouse buttons are pressed simultaneously
events.button==7 All three keys pressed

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn