Example usage for java.awt.event InputEvent META_DOWN_MASK

List of usage examples for java.awt.event InputEvent META_DOWN_MASK

Introduction

In this page you can find the example usage for java.awt.event InputEvent META_DOWN_MASK.

Prototype

int META_DOWN_MASK

To view the source code for java.awt.event InputEvent META_DOWN_MASK.

Click Source Link

Document

The Meta key extended modifier constant.

Usage

From source file:Main.java

static boolean isMetaDown(final InputEvent event) {
    final int modifiersEx = event.getModifiersEx();
    final int flag = modifiersEx & InputEvent.META_DOWN_MASK;
    return flag != 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

/**
 * Serializes a Keystrike to a String.//from w w  w  .  j av  a2  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   www .  j  a v a2s.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 ");
    }//w  w  w . j a  v  a2s .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 ");
    }//www . ja  v a 2s  . co 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:net.erdfelt.android.sdkfido.ui.SdkFidoFrame.java

private void enableExitKey() {
    InputMap rootInput = getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    ActionMap rootAction = getRootPane().getActionMap();

    if (SystemUtils.IS_OS_UNIX || SystemUtils.IS_OS_WINDOWS) {
        rootInput.put(KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.CTRL_DOWN_MASK), "exit");
        rootInput.put(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_DOWN_MASK), "exit");
    }/*w  w w  .j a  va  2 s  . co  m*/

    if (SystemUtils.IS_OS_MAC) {
        rootInput.put(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.META_DOWN_MASK), "exit");
    }

    rootAction.put("exit", new KeyAction(actionMapper, "exit"));
}

From source file:com.varaneckas.hawkscope.cfg.Configuration.java

/**
 * Parses hotkey string and returns int value of modifier.
 * I.e.: InputEvent.CTRL_DOWN_MASK//w w w .ja  v  a 2s .c  o  m
 * 
 * @return InputEvent modifier value
 */
public int getHotkeyModifier() {
    final String hotkey = properties.get(HOTKEY_REPR);
    if (hotkey != null && hotkey.contains("+")) {
        //good hotkey
        if (hotkey.startsWith("Shift")) {
            return InputEvent.SHIFT_DOWN_MASK;
        }
        if (hotkey.startsWith("Ctrl")) {
            return InputEvent.CTRL_DOWN_MASK;
        }
        if (hotkey.startsWith("Alt")) {
            return InputEvent.ALT_DOWN_MASK;
        }
        if (hotkey.startsWith("Win") || hotkey.startsWith("Command")) {
            return InputEvent.META_DOWN_MASK;
        }
    }
    //bad hotkey or no hotkey
    return -1;
}

From source file:util.ui.UiUtilities.java

/**
 * Registers the escape key as close key for a component.
 *
 * @param component//ww w . j  a  v a2s.  com
 *          The component to close on pressing escape key.
 */
public static void registerForClosing(final WindowClosingIf component) {
    Action a = new AbstractAction() {
        private static final long serialVersionUID = 1L;

        public void actionPerformed(ActionEvent e) {
            component.close();
        }
    };

    if (OperatingSystem.isMacOs()) {
        // Add MacOS Apple+W for Closing of Dialogs
        KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.META_DOWN_MASK);
        component.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, "CLOSE_ON_APPLE_W");
        component.getRootPane().getActionMap().put("CLOSE_ON_APPLE_W", a);

        stroke = KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.META_DOWN_MASK);
        component.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke,
                "CLOSE_COMPLETE_ON_APPLE");
        component.getRootPane().getActionMap().put("CLOSE_COMPLETE_ON_APPLE", new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                MainFrame.getInstance().quit();
            }
        });
    }

    KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    component.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, "CLOSE_ON_ESCAPE");
    component.getRootPane().getActionMap().put("CLOSE_ON_ESCAPE", a);
}