1 package jsystem.infra.util; 2 3 import java.awt.KeyEventDispatcher; 4 import java.awt.KeyboardFocusManager; 5 import java.awt.event.KeyEvent; 6 7 /** 8 * Class <code>CtrlListener</code> is used to detect whether the ctrl is pressed 9 * @author etxyzbh 10 * @version 14/12/2012 11 * 12 */ 13 public class CtrlListener { 14 private static boolean isCtrlDown; 15 16 static { 17 KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher( 18 new KeyEventDispatcher() { 19 public boolean dispatchKeyEvent(KeyEvent e) { 20 isCtrlDown = e.isControlDown(); 21 return false; 22 } 23 }); 24 } 25 26 /** 27 * 28 * @return the current status whether the ctrl is pressed 29 */ 30 public static boolean isCtrlDown() { 31 return isCtrlDown; 32 } 33 34 }