Home >Web Front-end >JS Tutorial >JS method to obtain the key values of the left and right mouse buttons_javascript skills
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