|
Author |
Topic: mouse buttons (Read 2145 times) |
|
benelek
|
mouse buttons
« on: Jan 9th, 2003, 9:04am » |
|
is there a way to determine which mouse button is being pressed?
|
|
|
|
fry
|
Re: mouse buttons
« Reply #1 on: Jan 9th, 2003, 4:19pm » |
|
there is a java MouseEvent object always available, called 'mouseEvent' that you can query. it's like 'pixels' or 'width', in that it's always available. but for clicks, you can write your own method that looks like: void mousePressed() { // do things to 'mouseEvent' here to get the buttons } this is a better option because you don't want the last mouseEvent to be mouse motion or a drag.. you just want clicks. that will get called whenever the mouse is pressed. or the more advanced (standard java) version: public void mousePressed(MouseEvent event) { // do things here } this works similarly for mouseClicked (single or double clicks, according to the java spec), mouseReleased, mouseMoved and mouseDragged.
|
|
|
|
benelek
|
Re: mouse buttons
« Reply #2 on: Jan 10th, 2003, 12:49pm » |
|
mm, what i meant is, which of the left or right mouse button is being pressed, etc. -jacob
|
« Last Edit: Jan 10th, 2003, 12:49pm by benelek » |
|
|
|
|
fry
|
Re: mouse buttons
« Reply #3 on: Jan 10th, 2003, 2:57pm » |
|
given that you have that MouseEvent, you use: Code:// button 2 if (mouseEvent.getModifiers() & InputEvent.BUTTON2_MASK) != 0) { // do something } // button 3 if (mouseEvent.getModifiers() & InputEvent.BUTTON3_MASK) != 0) { // do something } // 'alt' key if (mouseEvent.isAltDown()) { // do something } |
| keep in mind, though, that not all platforms/machines have more than one mouse button, so something like alt/option or shift plus a click might be better. a ctrl-click on the mac works if you use mouseEvent.isPopupTrigger() but that triggers in a weird way (on mouse down for mac and mouse up for pc, i believe).. so not so useful for dragging.
|
|
|
|
|