Java examples for Swing:Mouse Event
get Key Mask from MouseEvent
//package com.java2s; import java.awt.event.MouseEvent; public class Main { /** Mask for CTRL key pressed. */ public static final int MASK_CTRL = 0x1; /** Mask for ALT key pressed. */ public static final int MASK_ALT = 0x2; /** Mask for SHIFT key pressed. */ public static final int MASK_SHIFT = 0x4; /** Mask for ALT-GR key pressed. */ public static final int MASK_ALT_GR = 0x8; /**/*from w ww . j a v a2 s . c o m*/ * @param evt * The native mouse event to be handled. * @return The corresponding mask for the mouse-event. * @see #MASK_ALT * @see #MASK_ALT_GR * @see #MASK_CTRL * @see #MASK_SHIFT */ public static int getKeyMask(MouseEvent evt) { int mask = 0; if (evt.isAltDown()) { mask |= MASK_ALT; } if (evt.isAltGraphDown()) { mask |= MASK_ALT_GR; } if (evt.isControlDown()) { mask |= MASK_CTRL; } if (evt.isShiftDown()) { mask |= MASK_SHIFT; } return mask; } }