简体   繁体   English

如何确定在Java中是否单击了鼠标左键或右键?

[英]How do I determine if the left or right mouse button was clicked in Java?

I am trying to make a program in Java that uses both the left and right mouse buttons. 我正在尝试使用Java编写同时使用鼠标左键和鼠标右键的程序。 The default MouseMotionListener and MouseListener trigger for both mouse clicks. 默认的MouseMotionListenerMouseListener触发两次鼠标单击。

Is any way to determine what button is clicked? 有什么方法可以确定单击了哪个按钮?

Use the method getButton() 使用方法getButton()

It returns 1 for leftClick and 3 for rightClick . 为leftClick返回1, 为rightClick返回3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java如何判断鼠标键是否按下 - How do I determine if the mouse button is pressed in java 如何在单击按钮时从右向左滑动这些视图? - How can i slide these views from right to left on button clicked? 我正在尝试确定结果左侧和右侧的位数......(Java) - I'm trying to determine the number of digits to the left and the right of the result by…(Java) 如何在Selenium Webdriver(Java)中将鼠标从左向右悬停? - How to hover the mouse from left to right icons in selenium webdriver (Java)? 如何知道鼠标是否在Java中的jpanel中向左或向右拖动 - how to know if mouse dragged left or right inside jpanel in java 当单击鼠标时,应在main方法的哪里放置新的mouseListener来向CarShape左右动画? - Where should I place a new mouseListener in the main method to animate CarShape left or right when the mouse is clicked? 如何在JavaFX中区分鼠标左键和右键? - How to distinguish left and right mouse buttons in JavaFX? 如何检测 - 鼠标右键或左键是主键? - How to detect - mouse right or left key is primary? 如何确定 Swing 鼠标事件发生在哪个监视器中? - How do I determine which monitor a Swing mouse event occurs in? Android - 如何点击按钮我怎么记得? - Android - How do I remember if a button was clicked?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM