List of usage examples for java.awt.event InputEvent ALT_DOWN_MASK
int ALT_DOWN_MASK
To view the source code for java.awt.event InputEvent ALT_DOWN_MASK.
Click Source Link
From source file:Main.java
public static void main(String args[]) { JPanel JMainPanel = new JPanel(new BorderLayout()); JPanel jp = new JPanel(); JComboBox combo = new JComboBox(new String[] { "Item1", "Item2", "Item3" }); JPanel jImage = new JPanel(); JFrame jf = new JFrame(); jp.add(combo);//from www . j av a 2 s . c o m JMainPanel.add(jp, BorderLayout.WEST); JMainPanel.add(jImage, BorderLayout.CENTER); jp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.ALT_DOWN_MASK), "screenshot"); jp.getActionMap().put("screenshot", new AbstractAction() { @Override public void actionPerformed(ActionEvent arg0) { final BufferedImage bf = new BufferedImage(400, 400, BufferedImage.TYPE_INT_RGB); javax.swing.SwingUtilities.invokeLater(new Runnable() { @Override public void run() { jf.getRootPane().paint(bf.getGraphics()); jImage.getGraphics().drawImage(bf, 0, 0, jImage); } }); } }); jf.getContentPane().add(JMainPanel); jf.setSize(500, 500); jf.setVisible(true); }
From source file:Main.java
public static KeyStroke getAltKeyStroke(final int keyCode) { return KeyStroke.getKeyStroke(keyCode, InputEvent.ALT_DOWN_MASK); }
From source file:Main.java
/** Return true if the Alt button was held when 'e' was generated. */ public static boolean altPressed(InputEvent e) { return (e.getModifiersEx() & InputEvent.ALT_DOWN_MASK) != 0; }
From source file:Main.java
static boolean isModifierKeyDown(final InputEvent event) { final int modifiersEx = event.getModifiersEx(); final int flag = modifiersEx & (InputEvent.SHIFT_DOWN_MASK | InputEvent.ALT_DOWN_MASK | InputEvent.ALT_GRAPH_DOWN_MASK | InputEvent.CTRL_DOWN_MASK | InputEvent.META_DOWN_MASK); return flag != 0; }
From source file:Main.java
static boolean isAltDown(final InputEvent event) { final int modifiersEx = event.getModifiersEx(); final int flag = modifiersEx & InputEvent.ALT_DOWN_MASK; return flag != 0; }
From source file:Main.java
/** * Serializes a Keystrike to a String.//from w w w . jav a 2 s . c o m * It can then be fed into KeyStroke.getKeyStroke(String). * * See: http://www.exampledepot.com/egs/javax.swing/Key2Str.html */ public static String keyStroke2String(KeyStroke key) { StringBuffer s = new StringBuffer(50); int m = key.getModifiers(); if ((m & (InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK)) != 0) { s.append("shift "); } if ((m & (InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK)) != 0) { s.append("ctrl "); } if ((m & (InputEvent.META_DOWN_MASK | InputEvent.META_MASK)) != 0) { s.append("meta "); } if ((m & (InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK)) != 0) { s.append("alt "); } if ((m & (InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON1_MASK)) != 0) { s.append("button1 "); } if ((m & (InputEvent.BUTTON2_DOWN_MASK | InputEvent.BUTTON2_MASK)) != 0) { s.append("button2 "); } if ((m & (InputEvent.BUTTON3_DOWN_MASK | InputEvent.BUTTON3_MASK)) != 0) { s.append("button3 "); } switch (key.getKeyEventType()) { case KeyEvent.KEY_TYPED: if (key.getKeyChar() == Character.MAX_VALUE) { s.append("unknown-typed-key "); break; } s.append("typed ").append(key.getKeyChar()).append(" "); break; case KeyEvent.KEY_PRESSED: s.append("pressed ").append(getKeyText(key.getKeyCode())).append(" "); break; case KeyEvent.KEY_RELEASED: s.append("released ").append(getKeyText(key.getKeyCode())).append(" "); break; default: s.append("unknown-event-type "); break; } return s.toString(); }
From source file:KeystrokeUtil.java
public static String keyStroke2String(KeyStroke key) { if (key == null) return ""; StringBuilder s = new StringBuilder(50); int m = key.getModifiers(); if ((m & (InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK)) != 0) { s.append("Ctrl+"); }/*from w w w . j a v a 2 s . c o m*/ if ((m & (InputEvent.META_DOWN_MASK | InputEvent.META_MASK)) != 0) { s.append("Meta+"); } if ((m & (InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK)) != 0) { s.append("Alt+"); } if ((m & (InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK)) != 0) { s.append("Shift+"); } if ((m & (InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON1_MASK)) != 0) { s.append("Button1+"); } if ((m & (InputEvent.BUTTON2_DOWN_MASK | InputEvent.BUTTON2_MASK)) != 0) { s.append("Button2+"); } if ((m & (InputEvent.BUTTON3_DOWN_MASK | InputEvent.BUTTON3_MASK)) != 0) { s.append("Button3+"); } switch (key.getKeyEventType()) { case KeyEvent.KEY_TYPED: s.append(key.getKeyChar() + " "); break; case KeyEvent.KEY_PRESSED: case KeyEvent.KEY_RELEASED: s.append(getKeyText(key.getKeyCode()) + " "); break; default: s.append("unknown-event-type "); break; } return s.toString(); }
From source file:Main.java
static void keyStroke2String(KeyStroke key) { int m = key.getModifiers(); if ((m & (InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK)) != 0) { System.out.println("shift "); }//ww w .j a va 2 s. c o m if ((m & (InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK)) != 0) { System.out.println("ctrl "); } if ((m & (InputEvent.META_DOWN_MASK | InputEvent.META_MASK)) != 0) { System.out.println("meta "); } if ((m & (InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK)) != 0) { System.out.println("alt "); } if ((m & (InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON1_MASK)) != 0) { System.out.println("button1 "); } if ((m & (InputEvent.BUTTON2_DOWN_MASK | InputEvent.BUTTON2_MASK)) != 0) { System.out.println("button2 "); } if ((m & (InputEvent.BUTTON3_DOWN_MASK | InputEvent.BUTTON3_MASK)) != 0) { System.out.println("button3 "); } switch (key.getKeyEventType()) { case KeyEvent.KEY_TYPED: System.out.println("typed "); System.out.println(key.getKeyChar() + " "); break; case KeyEvent.KEY_PRESSED: System.out.println("pressed "); System.out.println(getKeyText(key.getKeyCode()) + " "); break; case KeyEvent.KEY_RELEASED: System.out.println("released "); System.out.println(getKeyText(key.getKeyCode()) + " "); break; default: System.out.println("unknown-event-type "); break; } }
From source file:Main.java
static void keyStroke2String(KeyStroke key) { int m = key.getModifiers(); if ((m & (InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK)) != 0) { System.out.println("shift "); }/*ww w . ja v a 2 s.c o m*/ if ((m & (InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK)) != 0) { System.out.println("ctrl "); } if ((m & (InputEvent.META_DOWN_MASK | InputEvent.META_MASK)) != 0) { System.out.println("meta "); } if ((m & (InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK)) != 0) { System.out.println("alt "); } if ((m & (InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON1_MASK)) != 0) { System.out.println("button1 "); } if ((m & (InputEvent.BUTTON2_DOWN_MASK | InputEvent.BUTTON2_MASK)) != 0) { System.out.println("button2 "); } if ((m & (InputEvent.BUTTON3_DOWN_MASK | InputEvent.BUTTON3_MASK)) != 0) { System.out.println("button3 "); } switch (key.getKeyEventType()) { case KeyEvent.KEY_TYPED: System.out.println("typed "); System.out.println(key.getKeyChar() + " "); break; case KeyEvent.KEY_PRESSED: System.out.println("pressed "); System.out.println(getKeyText(key.getKeyCode()) + " "); break; case KeyEvent.KEY_RELEASED: System.out.println("released "); System.out.println(getKeyText(key.getKeyCode()) + " "); break; default: System.out.println("unknown-event-type "); break; } }
From source file:SWTUtils.java
/** * Creates an AWT <code>MouseEvent</code> from a swt event. * This method helps passing SWT mouse event to awt components. * @param event The swt event.// w w w . jav a 2 s. co m * @return A AWT mouse event based on the given SWT event. */ public static MouseEvent toAwtMouseEvent(org.eclipse.swt.events.MouseEvent event) { int button = MouseEvent.NOBUTTON; switch (event.button) { case 1: button = MouseEvent.BUTTON1; break; case 2: button = MouseEvent.BUTTON2; break; case 3: button = MouseEvent.BUTTON3; break; } int modifiers = 0; if ((event.stateMask & SWT.CTRL) != 0) { modifiers |= InputEvent.CTRL_DOWN_MASK; } if ((event.stateMask & SWT.SHIFT) != 0) { modifiers |= InputEvent.SHIFT_DOWN_MASK; } if ((event.stateMask & SWT.ALT) != 0) { modifiers |= InputEvent.ALT_DOWN_MASK; } MouseEvent awtMouseEvent = new MouseEvent(DUMMY_PANEL, event.hashCode(), event.time, modifiers, event.x, event.y, 1, false, button); return awtMouseEvent; }