How can I check if the command/apple key is down on macs? I use right click in my game, but I would also like for mac users to be able to command + click. Now, I see isShiftDown, isControlDown, and isAltDown, but no isCommandDown or someting of that sort. I’m guessing you have to use the getModifiers command, but I cannot really test this as I have no immediate access to a computer running OS X.
I think there’s a method called KeyEvent.isMetaDown() or there is a KeyEvent.VK_META. I don’t have a Mac so don’t know for sure but I think that does the trick.
I’d actually like to know how the ‘windows’ key can be detected, if anyone knows?
there was some topic not so long ago about that… you need to include 3rd party libs for command or windows button to work since they are platform specific. There is a link to that libs… find topic.
Right click is performed by holding down control, not command. Also, I was under the impression that the control click was interpreted as a right cick automagically. I’ll test it this evening and let you know.
JPanel panel = new JPanel();
panel.addMouseListener(new MouseInputAdapter() {
public void mouseClicked(MouseEvent mouseEvent) {
System.out.println("Test.mouseClicked");
if (SwingUtilities.isLeftMouseButton(mouseEvent)) {
System.out.println("Left click");
}
if (SwingUtilities.isMiddleMouseButton(mouseEvent)) {
System.out.println("Middle click");
}
if (SwingUtilities.isRightMouseButton(mouseEvent)) {
System.out.println("Right click");
}
System.out.println("button = " + mouseEvent.getButton());
System.out.println("popupTrigger = " + mouseEvent.isPopupTrigger());
System.out.println("modifiers = " + mouseEvent.getModifiers());
System.out.println("modifiersEx = " + mouseEvent.getModifiersEx());
System.out.println("altDown = " + mouseEvent.isAltDown());
System.out.println("altGraphDown = " + mouseEvent.isAltGraphDown());
System.out.println("controlDown = " + mouseEvent.isControlDown());
System.out.println("metaDown = " + mouseEvent.isMetaDown());
System.out.println("shiftDown = " + mouseEvent.isShiftDown());
}
});
Using this bit of code I get the following results on my powerbook:
Control + click:
Test.mouseClicked
Left click
button = 1
popupTrigger = false
modifiers = 18
modifiersEx = 128
altDown = false
altGraphDown = false
controlDown = true
metaDown = false
shiftDown = false
Command + click:
Test.mouseClicked
Left click
Right click
button = 1
popupTrigger = false
modifiers = 20
modifiersEx = 256
altDown = false
altGraphDown = false
controlDown = false
metaDown = true
shiftDown = false
So no magic conversion from control click to right click. SwingUtilities does interpret meta (command) click as a right mouse button though. This is strange since the rest of the OS interprets control click as a right click.
Yeah, sorta odd
I had no clue the “apple” key was also refered to as “meta”
I did get it working with command + click in my checkers game, check it out in the games showcase if you want
[quote=“Death33284,post:6,topic:28104”]
That’s 'cause it isn’t :). The META key in the JRE is mapped to different keys on different platforms. I’m not sure, but I wouldn’t be surprized if it maps to the “windows” key that some PC keyboards have. On a Mac the “Apple” key is called the “Command” key. The “alt” key on a Mac is shown on the keyboard with the word “option” and “alt” in little tiny letters to the side.