Let's go.........RANDOM!
-
- level5
- Posts: 1187
- Joined: Fri Aug 31, 2007 4:37 pm
- Contact:
- bert_the_turtle
- level5
- Posts: 4795
- Joined: Fri Oct 13, 2006 6:11 pm
- Location: Cologne
- Contact:
- tabasco boy
- level5
- Posts: 1180
- Joined: Sun Mar 10, 2002 4:25 pm
- Location: Lovely Planet Earth
- Contact:
elexis wrote:Does anyone know how in Java I can check whether the shift key is pressed from within an ActionEventListener inner class for a button? Google doesn’t seem to be helping
isn't it something like:
public void keyPressed(KeyEvent e) {
// Handle the keys
switch (e.getKeyCode()) {
case VK_SHIFT:
System.out.printIn(" The Shift key was pressed." );
break;
}
}
don't hold me on it as i'm kinda rusty now.
What I want to do is make the button do something different when the shift key is pressed when you click it. Currently I am using a MouseEventListener which allows me to to pretty much what tabasco boy said on MouseClick but ive noticed that you sometimes need to Click/Shift-Click the button several times before anything happens. I am assuming this is because im not using the preferable ActionEventListener to check if the button is being used. The problem is i cant find any way to check if the key (shift is a modifier key) is down or not without using the MouseEvent of KeyEvent listeners. I *could* put a Key listener in EVERY focusable object in the gui which checks this but thats horrible inefficient.
- Ace Rimmer
- level5
- Posts: 10803
- Joined: Thu Dec 07, 2006 9:46 pm
- Location: The Multiverse
-
- Site Admin
- Posts: 1783
- Joined: Sat Mar 14, 2009 1:48 am
- Location: North of the Wall
- Contact:
Who is online
Users browsing this forum: No registered users and 31 guests