本文整理匯總了Java中javax.swing.KeyStroke.getKeyCode方法的典型用法代碼示例。如果您正苦於以下問題:Java KeyStroke.getKeyCode方法的具體用法?Java KeyStroke.getKeyCode怎麽用?Java KeyStroke.getKeyCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.KeyStroke
的用法示例。
在下文中一共展示了KeyStroke.getKeyCode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: findKey
import javax.swing.KeyStroke; //導入方法依賴的package包/類
/** Same method as above, but works just with plain actions.
*/
private static String findKey(Action action) {
if (action == null) {
return null;
}
KeyStroke accelerator = (KeyStroke) action.getValue(Action.ACCELERATOR_KEY);
if (accelerator == null) {
return null;
}
int modifiers = accelerator.getModifiers();
String acceleratorText = ""; // NOI18N
if (modifiers > 0) {
acceleratorText = KeyEvent.getKeyModifiersText(modifiers);
acceleratorText += "+"; // NOI18N
} else if (accelerator.getKeyCode() == KeyEvent.VK_UNDEFINED) {
return ""; // NOI18N
}
acceleratorText += KeyEvent.getKeyText(accelerator.getKeyCode());
return acceleratorText;
}
示例2: keyStrokeToString
import javax.swing.KeyStroke; //導入方法依賴的package包/類
/**
* Creates nice textual representation of KeyStroke.
* Modifiers and an actual key label are concated by plus signs
* @param the KeyStroke to get description of
* @return String describing the KeyStroke
*/
public static String keyStrokeToString( KeyStroke stroke ) {
String modifText = KeyEvent.getKeyModifiersText( stroke.getModifiers() );
String keyText = (stroke.getKeyCode() == KeyEvent.VK_UNDEFINED) ?
String.valueOf(stroke.getKeyChar()) : getKeyText(stroke.getKeyCode());
if( modifText.length() > 0 ) return modifText + '+' + keyText;
else return keyText;
}
示例3: keyStrokeToString
import javax.swing.KeyStroke; //導入方法依賴的package包/類
public static String keyStrokeToString(KeyStroke keyStroke) {
int modifiers = keyStroke.getModifiers();
StringBuffer sb = new StringBuffer();
if ((modifiers & InputEvent.CTRL_DOWN_MASK) > 0) {
sb.append("Ctrl+"); // NOI18N
}
if ((modifiers & InputEvent.ALT_DOWN_MASK) > 0) {
sb.append("Alt+"); // NOI18N
}
if ((modifiers & InputEvent.SHIFT_DOWN_MASK) > 0) {
sb.append("Shift+"); // NOI18N
}
if ((modifiers & InputEvent.META_DOWN_MASK) > 0) {
sb.append("Meta+"); // NOI18N
}
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();
}
示例4: keyCommand
import javax.swing.KeyStroke; //導入方法依賴的package包/類
/**
* Classes other than the Chatter itself may forward KeyEvents
* to the Chatter by using this method
*/
public void keyCommand(KeyStroke e) {
if ((e.getKeyCode() == 0 || e.getKeyCode() == KeyEvent.CHAR_UNDEFINED)
&& !Character.isISOControl(e.getKeyChar())) {
input.setText(input.getText() + e.getKeyChar());
}
else if (e.isOnKeyRelease()) {
switch (e.getKeyCode()) {
case KeyEvent.VK_ENTER:
if (input.getText().length() > 0)
send(formatChat(input.getText()));
input.setText(""); //$NON-NLS-1$
break;
case KeyEvent.VK_BACK_SPACE:
case KeyEvent.VK_DELETE:
String s = input.getText();
if (s.length() > 0)
input.setText(s.substring(0, s.length() - 1));
break;
}
}
}
示例5: getKeyStrokeAsText
import javax.swing.KeyStroke; //導入方法依賴的package包/類
/**
* Get human-readable name for a {@link KeyStroke}.
*/
public static String getKeyStrokeAsText(@NonNull KeyStroke keyStroke) {
int modifiers = keyStroke.getModifiers ();
StringBuilder sb = new StringBuilder ();
if ((modifiers & InputEvent.CTRL_DOWN_MASK) > 0) {
sb.append(EMACS_CTRL);
}
if ((modifiers & InputEvent.ALT_DOWN_MASK) > 0) {
sb.append(STRING_ALT);
}
if ((modifiers & InputEvent.SHIFT_DOWN_MASK) > 0) {
sb.append (EMACS_SHIFT);
}
if ((modifiers & InputEvent.META_DOWN_MASK) > 0) {
sb.append(STRING_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 ();
}
示例6: getKeyStrokeAsText
import javax.swing.KeyStroke; //導入方法依賴的package包/類
private static String getKeyStrokeAsText(KeyStroke keyStroke) {
int modifiers = keyStroke.getModifiers();
StringBuilder sb = new StringBuilder();
sb.append('\'');
if ((modifiers & InputEvent.CTRL_DOWN_MASK) > 0) {
sb.append("Ctrl+"); //NOI18N
}
if ((modifiers & InputEvent.ALT_DOWN_MASK) > 0) {
sb.append("Alt+"); //NOI18N
}
if ((modifiers & InputEvent.SHIFT_DOWN_MASK) > 0) {
sb.append("Shift+"); //NOI18N
}
if ((modifiers & InputEvent.META_DOWN_MASK) > 0) {
sb.append("Meta+"); //NOI18N
}
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(org.openide.util.Utilities.keyToString(
KeyStroke.getKeyStroke(keyStroke.getKeyCode(), 0)
));
}
sb.append('\'');
return sb.toString();
}
示例7: listKeyReleased
import javax.swing.KeyStroke; //導入方法依賴的package包/類
private void listKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_listKeyReleased
KeyStroke ks = KeyStroke.getKeyStrokeForEvent(evt);
if ( ks.getKeyCode() == KeyEvent.VK_ENTER ||
ks.getKeyCode() == KeyEvent.VK_SPACE ) {
importClass(
getSelected(),
(evt.getModifiers() & (org.openide.util.Utilities.isMac() ? InputEvent.META_MASK : InputEvent.ALT_MASK)) > 0,
(evt.getModifiers() & InputEvent.SHIFT_MASK) > 0);
}
}
示例8: getKeyStrokeAsText
import javax.swing.KeyStroke; //導入方法依賴的package包/類
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 ();
}
示例9: getKeys
import javax.swing.KeyStroke; //導入方法依賴的package包/類
private static CharSequence getKeys(String keysFor, String sKeyStroke) {
KeyStroke ks = KeyStroke.getKeyStroke(sKeyStroke);
if (ks == null) {
throw new WebDriverException("Unable to parse keystroke for " + keysFor + " trying to parse " + sKeyStroke);
}
StringBuilder sb = new StringBuilder();
int modifiers = ks.getModifiers();
if ((modifiers & InputEvent.CTRL_DOWN_MASK) == InputEvent.CTRL_DOWN_MASK) {
sb.append(Keys.CONTROL);
}
if ((modifiers & InputEvent.ALT_DOWN_MASK) == InputEvent.ALT_DOWN_MASK) {
sb.append(Keys.ALT);
}
if ((modifiers & InputEvent.META_DOWN_MASK) == InputEvent.META_DOWN_MASK) {
sb.append(Keys.META);
}
if ((modifiers & InputEvent.SHIFT_DOWN_MASK) == InputEvent.SHIFT_DOWN_MASK) {
sb.append(Keys.SHIFT);
}
int keyCode = ks.getKeyCode();
if (keyCode == KeyEvent.VK_UNDEFINED) {
sb.append(ks.getKeyChar());
} else {
sb.append(keyCharFromKeyCode(keyCode, keysFor));
}
sb.append(Keys.NULL);
return sb.toString();
}
示例10: encode
import javax.swing.KeyStroke; //導入方法依賴的package包/類
/**
* Encode a NamedKeyStroke into a String
*/
public static String encode(NamedKeyStroke stroke) {
if (stroke == null) {
return "";
}
KeyStroke key = stroke.getStroke();
if (key == null) {
return "";
}
String s = key.getKeyCode() + "," + key.getModifiers();
if (stroke.isNamed()) {
s += "," + stroke.getName();
}
return s;
}
示例11: isNamed
import javax.swing.KeyStroke; //導入方法依賴的package包/類
/**
* Return true if the supplied KeyStroke is in the range allocated
* to NamedKeyStrokes
* @param k KeyStroke
* @return true if this was generated by us
*/
public static boolean isNamed(KeyStroke k) {
if (k == null) {
return false;
}
int code = k.getKeyCode();
return code == NAMED_MARKER || (code >= NAMED_START && code <= NAMED_END);
}
示例12: removeKeyStroke
import javax.swing.KeyStroke; //導入方法依賴的package包/類
/**
* Removes the given {@code KeyStroke}. That is:
* This action's {@code KeyStroke} is set to
* {@code null} if it is the same as the given
* {@code KeyStroke}.
*
* @param k The {@code KeyStroke} to be removed.
*/
public void removeKeyStroke(KeyStroke k) {
if (k != null && keyStroke != null
&& k.getKeyCode() == keyStroke.getKeyCode()
&& k.getModifiers() == keyStroke.getModifiers()) {
keyStroke = null;
bl.setText(" ");
}
}
示例13: getAction
import javax.swing.KeyStroke; //導入方法依賴的package包/類
public Action getAction(final KeyStroke key) {
switch (key.getKeyCode()) {
case KeyEvent.VK_SHIFT:
case KeyEvent.VK_CONTROL:
case KeyEvent.VK_ALT:
case KeyEvent.VK_ALT_GRAPH:
case KeyEvent.VK_META:
case KeyEvent.VK_UNDEFINED:
case KeyEvent.CHAR_UNDEFINED:
// Not actually a bindable key press.
return null;
}
if (key.isOnKeyRelease()) {
// Again, not really our business here.
return null;
}
LOG.log(Level.FINE, "getAction {0}", key);
Map<KeyStroke,Binding> binder = bindings();
for (KeyStroke ctx : context) {
Binding sub = binder.get(ctx);
if (sub == null) {
resetContext();
return BROKEN; // no entry found after known prefix
}
binder = sub.nested;
if (binder == null) {
resetContext();
return BROKEN; // anomalous, expected to find submap here
}
}
Binding b = binder.get(key);
if (b == null) {
resetContext();
return null; // normal, not found
}
if (b.nested == null) {
resetContext();
return b.loadAction(); // found real action
} else {
return new AbstractAction() {
public void actionPerformed(ActionEvent e) {
shiftContext(key); // entering submap
}
};
}
}
示例14: actionPerformed
import javax.swing.KeyStroke; //導入方法依賴的package包/類
@Override
public void actionPerformed(ActionEvent evt) {
boolean editors = true;
boolean views = !documentsOnly;
if( "immediately".equals( evt.getActionCommand() ) ) {
TopComponent activeTc = TopComponent.getRegistry().getActivated();
if( null != activeTc ) {
if( TopComponentTracker.getDefault().isEditorTopComponent( activeTc ) ) {
//switching in a document, go to some other document
views = false;
} else {
//switching in a view, go to some other view
editors = false;
views = true;
}
}
}
TopComponent[] documents = getRecentWindows(editors, views);
if (documents.length < 2) {
return;
}
if(!"immediately".equals(evt.getActionCommand()) && // NOI18N
!(evt.getSource() instanceof javax.swing.JMenuItem)) {
// #46800: fetch key directly from action command
KeyStroke keyStroke = Utilities.stringToKey(evt.getActionCommand());
if(keyStroke != null) {
int triggerKey = keyStroke.getKeyCode();
int reverseKey = KeyEvent.VK_SHIFT;
int releaseKey = 0;
int modifiers = keyStroke.getModifiers();
if((InputEvent.CTRL_MASK & modifiers) != 0) {
releaseKey = KeyEvent.VK_CONTROL;
} else if((InputEvent.ALT_MASK & modifiers) != 0) {
releaseKey = KeyEvent.VK_ALT;
} else if((InputEvent.META_MASK & modifiers) != 0) {
releaseKey = KeyEvent.VK_META;
}
if(releaseKey != 0) {
if (!KeyboardPopupSwitcher.isShown()) {
KeyboardPopupSwitcher.showPopup(documentsOnly, releaseKey, triggerKey, (evt.getModifiers() & KeyEvent.SHIFT_MASK) == 0);
}
return;
}
}
}
int documentIndex = (evt.getModifiers() & KeyEvent.SHIFT_MASK) == 0 ? 1 : documents.length-1;
TopComponent tc = documents[documentIndex];
// #37226 Unmaximized the other mode if needed.
WindowManagerImpl wm = WindowManagerImpl.getInstance();
ModeImpl mode = (ModeImpl) wm.findMode(tc);
if(mode != null && mode != wm.getCurrentMaximizedMode()) {
wm.switchMaximizedMode(null);
}
tc.requestActive();
}
示例15: listKeyReleased
import javax.swing.KeyStroke; //導入方法依賴的package包/類
private void listKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_listKeyReleased
KeyStroke ks = KeyStroke.getKeyStrokeForEvent(evt);
if (ks.getKeyCode() == KeyEvent.VK_ENTER || ks.getKeyCode() == KeyEvent.VK_SPACE) {
invokeSelected();
}
}