当前位置: 首页>>代码示例>>Java>>正文


Java KeyEvent.VK_ALT属性代码示例

本文整理汇总了Java中java.awt.event.KeyEvent.VK_ALT属性的典型用法代码示例。如果您正苦于以下问题:Java KeyEvent.VK_ALT属性的具体用法?Java KeyEvent.VK_ALT怎么用?Java KeyEvent.VK_ALT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在java.awt.event.KeyEvent的用法示例。


在下文中一共展示了KeyEvent.VK_ALT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: keyReleased

public void keyReleased(KeyEvent e) {
    // Fix (workaround) for issue #186557
    if (org.openide.util.Utilities.isWindows()) {
        if (Boolean.getBoolean("HintsUI.disable.AltEnter.hack")) { // NOI18N
            return;
        }

        if (altEnterPressed && e.getKeyCode() == KeyEvent.VK_ALT) {
            e.consume();
            altReleased = true;
        } else if (altEnterPressed && e.getKeyCode() == KeyEvent.VK_ENTER) {
            altEnterPressed = false;
            if (altReleased) {
                try {
                    java.awt.Robot r = new java.awt.Robot();
                    r.keyRelease(KeyEvent.VK_ALT);
                } catch (AWTException ex) {
                    Exceptions.printStackTrace(ex);
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:HintsUI.java

示例2: keyPressed

@Override
public void keyPressed(KeyEvent e) {
    int keyCode = e.getKeyCode();
    char keyChar = e.getKeyChar();

    switch (state) {
        case 0:
            if (keyCode != KeyEvent.VK_ALT) {
                throw new RuntimeException("Alt is not pressed.");
            }
            state++;
            break;
        case 1:
            if (keyCode != KeyEvent.VK_DEAD_ACUTE) {
                throw new RuntimeException("Dead ACUTE is not pressed.");
            }
            if (keyChar != 0xB4) {
                throw new RuntimeException("Pressed char is not dead acute.");
            }
            state++;
            break;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:DeadKeyMacOSXInputText.java

示例3: postProcessKeyEvent

public boolean postProcessKeyEvent(KeyEvent ev) {
    if(ev.isConsumed() && ev.getKeyCode() != KeyEvent.VK_ALT) {
        // mnemonic combination, it's consumed, but we need
        // set altKeyPressed to false, otherwise after selection
        // component by mnemonic combination a menu will be open
        altKeyPressed = false;
        return false;
    }
    if (ev.getKeyCode() == KeyEvent.VK_ALT) {
        root = SwingUtilities.getRootPane(ev.getComponent());
        winAncestor = (root == null ? null :
                SwingUtilities.getWindowAncestor(root));

        if (ev.getID() == KeyEvent.KEY_PRESSED) {
            if (!altKeyPressed) {
                altPressed(ev);
            }
            altKeyPressed = true;
            return true;
        } else if (ev.getID() == KeyEvent.KEY_RELEASED) {
            if (altKeyPressed) {
                altReleased(ev);
            } else {
                MenuSelectionManager msm =
                    MenuSelectionManager.defaultManager();
                MenuElement[] path = msm.getSelectedPath();
                if (path.length <= 0) {
                    WindowsLookAndFeel.setMnemonicHidden(true);
                    WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
                }
            }
            altKeyPressed = false;
        }
        root = null;
        winAncestor = null;
    } else {
        altKeyPressed = false;
    }
    return false;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:40,代码来源:WindowsRootPaneUI.java

示例4: keyPressed

@Override
public void keyPressed(Canvas canvas, KeyEvent e) {
	int code = e.getKeyCode();
	if (active && (code == KeyEvent.VK_SHIFT || code == KeyEvent.VK_ALT || code == KeyEvent.VK_CONTROL)) {
		updateMouse(canvas, lastMouseX, lastMouseY, e.getModifiersEx());
	}
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:7,代码来源:RectangularTool.java

示例5: postProcessKeyEvent

public boolean postProcessKeyEvent(final KeyEvent ev) {
    if (ev.getKeyCode() != KeyEvent.VK_ALT) {
        return false;
    }

    final JRootPane root = SwingUtilities.getRootPane(ev.getComponent());
    final Window winAncestor = (root == null ? null : SwingUtilities.getWindowAncestor(root));

    switch(ev.getID()) {
        case KeyEvent.KEY_PRESSED:
            setMnemonicHidden(false);
            break;
        case KeyEvent.KEY_RELEASED:
            setMnemonicHidden(true);
            break;
    }

    repaintMnemonicsInWindow(winAncestor);

    return false;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:AquaMnemonicHandler.java

示例6: menuItem

/** Construct a new JMenuItem then add it to an existing JMenu.
 * @param parent - the JMenu to add this JMenuItem into (or null if you don't want to add it to any JMenu yet)
 * @param label - the text to show on the menu
 * @param attrs - a list of attributes to apply onto the new JMenuItem
 * <p> If one positive number  a is supplied, we call setMnemonic(a)
 * <p> If two positive numbers a and b are supplied, and a!=VK_ALT, and a!=VK_SHIFT, we call setMnemoic(a) and setAccelerator(b)
 * <p> If two positive numbers a and b are supplied, and a==VK_ALT or a==VK_SHIFT, we call setAccelerator(a | b)
 * <p> If an ActionListener is supplied, we call addActionListener(x)
 * <p> If an Boolean x      is supplied, we call setEnabled(x)
 * <p> If an Icon x         is supplied, we call setIcon(x)
 */
public static JMenuItem menuItem (JMenu parent, String label, Object... attrs) {
   JMenuItem m = new JMenuItem(label, null);
   int accelMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
   boolean hasMnemonic = false;
   for(Object x: attrs) {
      if (x instanceof Character || x instanceof Integer) {
         int k = (x instanceof Character) ? ((int)((Character)x)) : ((Integer)x).intValue();
         if (k < 0) continue;
         if (k==KeyEvent.VK_ALT)   { hasMnemonic = true; accelMask = accelMask | InputEvent.ALT_MASK;   continue; }
         if (k==KeyEvent.VK_SHIFT) { hasMnemonic = true; accelMask = accelMask | InputEvent.SHIFT_MASK; continue; }
         if (!hasMnemonic) { m.setMnemonic(k); hasMnemonic=true; } else m.setAccelerator(KeyStroke.getKeyStroke(k, accelMask));
      }
      if (x instanceof ActionListener) m.addActionListener((ActionListener)x);
      if (x instanceof Icon) m.setIcon((Icon)x);
      if (x instanceof Boolean) m.setEnabled((Boolean)x);
   }
   if (parent!=null) parent.add(m);
   return m;
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:30,代码来源:OurUtil.java

示例7: menuItem

/**
 * Construct a new JMenuItem then add it to an existing JMenu.
 * 
 * @param parent - the JMenu to add this JMenuItem into (or null if you
 *            don't want to add it to any JMenu yet)
 * @param label - the text to show on the menu
 * @param attrs - a list of attributes to apply onto the new JMenuItem
 *            <p>
 *            If one positive number a is supplied, we call setMnemonic(a)
 *            <p>
 *            If two positive numbers a and b are supplied, and a!=VK_ALT,
 *            and a!=VK_SHIFT, we call setMnemoic(a) and setAccelerator(b)
 *            <p>
 *            If two positive numbers a and b are supplied, and a==VK_ALT or
 *            a==VK_SHIFT, we call setAccelerator(a | b)
 *            <p>
 *            If an ActionListener is supplied, we call addActionListener(x)
 *            <p>
 *            If an Boolean x is supplied, we call setEnabled(x)
 *            <p>
 *            If an Icon x is supplied, we call setIcon(x)
 */
public static JMenuItem menuItem(JMenu parent, String label, Object... attrs) {
	JMenuItem m = new JMenuItem(label, null);
	int accelMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
	boolean hasMnemonic = false;
	for (Object x : attrs) {
		if (x instanceof Character || x instanceof Integer) {
			int k = (x instanceof Character) ? ((int) ((Character) x)) : ((Integer) x).intValue();
			if (k < 0)
				continue;
			if (k == KeyEvent.VK_ALT) {
				hasMnemonic = true;
				accelMask = accelMask | InputEvent.ALT_MASK;
				continue;
			}
			if (k == KeyEvent.VK_SHIFT) {
				hasMnemonic = true;
				accelMask = accelMask | InputEvent.SHIFT_MASK;
				continue;
			}
			if (!hasMnemonic) {
				m.setMnemonic(k);
				hasMnemonic = true;
			} else
				m.setAccelerator(KeyStroke.getKeyStroke(k, accelMask));
		}
		if (x instanceof ActionListener)
			m.addActionListener((ActionListener) x);
		if (x instanceof Icon)
			m.setIcon((Icon) x);
		if (x instanceof Boolean)
			m.setEnabled((Boolean) x);
	}
	if (parent != null)
		parent.add(m);
	return m;
}
 
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:58,代码来源:OurUtil.java

示例8: keyReleased

@Override
public void keyReleased(KeyEvent ke) {
    int k = ke.getKeyCode();
    if (k == KeyEvent.VK_SHIFT) {
        shiftPressed = false;
    } else if (k == KeyEvent.VK_CONTROL) {
        ctlPressed = false;
    } else if (k == KeyEvent.VK_ALT) {
        altPressed = false;
    } else if (k == KeyEvent.VK_E) {
        setEraseSamplesEnabled(false);
    }
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:13,代码来源:TargetLabeler.java

示例9: ModifierRobotKeyTest

public ModifierRobotKeyTest() throws Exception {
    modifierKeys =  new int[4];
    modifierKeys[0] = KeyEvent.VK_SHIFT;
    modifierKeys[1] = KeyEvent.VK_CONTROL;
    modifierKeys[2] = KeyEvent.VK_ALT;
    modifierKeys[3] = KeyEvent.VK_ALT_GRAPH;

    inputMasks = new int[4];
    inputMasks[0] =  InputEvent.SHIFT_MASK;
    inputMasks[1] =  InputEvent.CTRL_MASK;
    inputMasks[2] =  InputEvent.ALT_MASK;
    inputMasks[3] =  InputEvent.ALT_GRAPH_MASK;

    modifierStatus = new boolean[modifierKeys.length];

    textKeys = new int[2];
    textKeys[0] = KeyEvent.VK_A;

    String os = System.getProperty("os.name").toLowerCase();

    if (os.contains("solaris") || os.contains("sunos"))
        textKeys[1] = KeyEvent.VK_S;
    else if (os.contains("os x"))
        textKeys[1] = KeyEvent.VK_K;
    else
        textKeys[1] = KeyEvent.VK_I;

    textStatus = new boolean[textKeys.length];

    EventQueue.invokeAndWait( () -> { initializeGUI(); });
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:ModifierRobotKeyTest.java

示例10: postProcessKeyEvent

public boolean postProcessKeyEvent(KeyEvent ev) {
    if(ev.isConsumed()) {
        // do not manage consumed event
        return false;
    }
    if (ev.getKeyCode() == KeyEvent.VK_ALT) {
        root = SwingUtilities.getRootPane(ev.getComponent());
        winAncestor = (root == null ? null :
                SwingUtilities.getWindowAncestor(root));

        if (ev.getID() == KeyEvent.KEY_PRESSED) {
            if (!altKeyPressed) {
                altPressed(ev);
            }
            altKeyPressed = true;
            return true;
        } else if (ev.getID() == KeyEvent.KEY_RELEASED) {
            if (altKeyPressed) {
                altReleased(ev);
            } else {
                MenuSelectionManager msm =
                    MenuSelectionManager.defaultManager();
                MenuElement[] path = msm.getSelectedPath();
                if (path.length <= 0) {
                    WindowsLookAndFeel.setMnemonicHidden(true);
                    WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
                }
            }
            altKeyPressed = false;
        }
        root = null;
        winAncestor = null;
    } else {
        altKeyPressed = false;
    }
    return false;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:37,代码来源:WindowsRootPaneUI.java

示例11: getKeyStrokeAsText

static String getKeyStrokeAsText (KeyStroke keyStroke) {
    if (keyStroke == null)
        return "";
    int modifiers = keyStroke.getModifiers ();
    StringBuffer sb = new StringBuffer ();
    if ((modifiers & InputEvent.CTRL_DOWN_MASK) > 0)
        sb.append ("Ctrl+");
    if ((modifiers & InputEvent.ALT_DOWN_MASK) > 0)
        sb.append ("Alt+");
    if ((modifiers & InputEvent.SHIFT_DOWN_MASK) > 0)
        sb.append ("Shift+");
    if ((modifiers & InputEvent.META_DOWN_MASK) > 0)
        if (Utilities.isMac()) {
            // Mac cloverleaf symbol
            sb.append ("\u2318+");
        } else if (isSolaris()) {
            // Sun meta symbol
            sb.append ("\u25C6+");
        } else {
            sb.append ("Meta+");
        }
    if (keyStroke.getKeyCode () != KeyEvent.VK_SHIFT &&
        keyStroke.getKeyCode () != KeyEvent.VK_CONTROL &&
        keyStroke.getKeyCode () != KeyEvent.VK_META &&
        keyStroke.getKeyCode () != KeyEvent.VK_ALT &&
        keyStroke.getKeyCode () != KeyEvent.VK_ALT_GRAPH
    )
        sb.append (Utilities.keyToString (
            KeyStroke.getKeyStroke (keyStroke.getKeyCode (), 0)
        ));
    return sb.toString ();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:SearchResultRender.java

示例12: eventDispatched

public void eventDispatched(AWTEvent event) {
    if (!(event instanceof KeyEvent)) {
        return;
    }
    KeyEvent keyEvent = (KeyEvent)event;
    if (keyEvent.getKeyCode() == KeyEvent.VK_ALT) {
        Toolkit.getDefaultToolkit().removeAWTEventListener(this);
        KeyEvent kev = new KeyEvent(
            (Component)keyEvent.getSource(), KeyEvent.KEY_RELEASED, keyEvent.getWhen(),
            keyEvent.getModifiers(), keyEvent.getKeyCode(), keyEvent.getKeyChar()

        );
        KeyboardPopupSwitcher.processInterruption(kev);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:KeyboardPopupSwitcher.java

示例13: getModifier

private int getModifier(int keycode) {
    switch (keycode) {
    case KeyEvent.VK_SHIFT:
        return InputEvent.SHIFT_MASK;
    case KeyEvent.VK_CONTROL:
        return InputEvent.CTRL_MASK;
    case KeyEvent.VK_ALT:
        return InputEvent.ALT_MASK;
    case KeyEvent.VK_META:
        return InputEvent.META_MASK;
    default:
        throw new RuntimeException(OSUtils.keyEventGetKeyText(keycode) + " is not a valid modifier");
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:14,代码来源:KeyStrokeParser.java

示例14: recordRawKeyEvent

@Override public void recordRawKeyEvent(RComponent r, KeyEvent e) {
    JSONObject event = new JSONObject();
    event.put("type", "key_raw");
    int keyCode = e.getKeyCode();
    if (keyCode == KeyEvent.VK_META || keyCode == KeyEvent.VK_SHIFT || keyCode == KeyEvent.VK_ALT
            || keyCode == KeyEvent.VK_CONTROL) {
        return;
    }
    if ((e.isActionKey() || e.isControlDown() || e.isMetaDown() || e.isAltDown()) && e.getID() == KeyEvent.KEY_PRESSED) {
        String mtext = buildModifiersText(e);
        event.put("modifiersEx", mtext);
        KeysMap keysMap = KeysMap.findMap(e.getKeyCode());
        if (keysMap == KeysMap.NULL) {
            return;
        }
        String keyText;
        if (keysMap == null) {
            keyText = KeyEvent.getKeyText(e.getKeyCode());
        } else {
            keyText = keysMap.toString();
        }
        event.put("keyCode", keyText);
    } else if (e.getID() == KeyEvent.KEY_TYPED && !e.isControlDown()) {
        if (Character.isISOControl(e.getKeyChar()) && hasMapping(e.getKeyChar())) {
            event.put("keyChar", getMapping(e.getKeyChar()));
        } else {
            event.put("keyChar", "" + e.getKeyChar());
        }
    } else {
        return;
    }
    recordEvent(r, event);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:33,代码来源:WSRecorder.java

示例15: keyPressed

public void keyPressed(KeyEvent e) {
  switch (e.getKeyCode()) {
    case KeyEvent.VK_DELETE:
    case KeyEvent.VK_BACK_SPACE:
      setValue(null);
      break;
    case KeyEvent.VK_SHIFT:
    case KeyEvent.VK_CONTROL:
    case KeyEvent.VK_META:
    case KeyEvent.VK_ALT:
      break;
    default:
      setValue(KeyStroke.getKeyStrokeForEvent(e));
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:15,代码来源:HotKeyConfigurer.java


注:本文中的java.awt.event.KeyEvent.VK_ALT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。