本文整理匯總了Java中java.awt.event.KeyEvent.KEY_RELEASED屬性的典型用法代碼示例。如果您正苦於以下問題:Java KeyEvent.KEY_RELEASED屬性的具體用法?Java KeyEvent.KEY_RELEASED怎麽用?Java KeyEvent.KEY_RELEASED使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類java.awt.event.KeyEvent
的用法示例。
在下文中一共展示了KeyEvent.KEY_RELEASED屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getAWTKeyStrokeForEvent
/**
* Returns an <code>AWTKeyStroke</code> which represents the
* stroke which generated a given <code>KeyEvent</code>.
* <p>
* This method obtains the keyChar from a <code>KeyTyped</code>
* event, and the keyCode from a <code>KeyPressed</code> or
* <code>KeyReleased</code> event. The <code>KeyEvent</code> modifiers are
* obtained for all three types of <code>KeyEvent</code>.
*
* @param anEvent the <code>KeyEvent</code> from which to
* obtain the <code>AWTKeyStroke</code>
* @throws NullPointerException if <code>anEvent</code> is null
* @return the <code>AWTKeyStroke</code> that precipitated the event
*/
public static AWTKeyStroke getAWTKeyStrokeForEvent(KeyEvent anEvent) {
int id = anEvent.getID();
switch(id) {
case KeyEvent.KEY_PRESSED:
case KeyEvent.KEY_RELEASED:
return getCachedStroke(KeyEvent.CHAR_UNDEFINED,
anEvent.getKeyCode(),
anEvent.getModifiers(),
(id == KeyEvent.KEY_RELEASED));
case KeyEvent.KEY_TYPED:
return getCachedStroke(anEvent.getKeyChar(),
KeyEvent.VK_UNDEFINED,
anEvent.getModifiers(),
false);
default:
// Invalid ID for this KeyEvent
return null;
}
}
示例2: getAWTKeyStrokeForEvent
/**
* Returns an {@code AWTKeyStroke} which represents the
* stroke which generated a given {@code KeyEvent}.
* <p>
* This method obtains the keyChar from a {@code KeyTyped}
* event, and the keyCode from a {@code KeyPressed} or
* {@code KeyReleased} event. The {@code KeyEvent} modifiers are
* obtained for all three types of {@code KeyEvent}.
*
* @param anEvent the {@code KeyEvent} from which to
* obtain the {@code AWTKeyStroke}
* @throws NullPointerException if {@code anEvent} is null
* @return the {@code AWTKeyStroke} that precipitated the event
*/
@SuppressWarnings("deprecation")
public static AWTKeyStroke getAWTKeyStrokeForEvent(KeyEvent anEvent) {
int id = anEvent.getID();
switch(id) {
case KeyEvent.KEY_PRESSED:
case KeyEvent.KEY_RELEASED:
return getCachedStroke(KeyEvent.CHAR_UNDEFINED,
anEvent.getKeyCode(),
anEvent.getModifiers(),
(id == KeyEvent.KEY_RELEASED));
case KeyEvent.KEY_TYPED:
return getCachedStroke(anEvent.getKeyChar(),
KeyEvent.VK_UNDEFINED,
anEvent.getModifiers(),
false);
default:
// Invalid ID for this KeyEvent
return null;
}
}
示例3: handleShortcut
@SuppressWarnings("deprecation")
boolean handleShortcut(KeyEvent e) {
// Is it a key event?
int id = e.getID();
if (id != KeyEvent.KEY_PRESSED && id != KeyEvent.KEY_RELEASED) {
return false;
}
// Is the accelerator modifier key pressed?
int accelKey = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
if ((e.getModifiers() & accelKey) == 0) {
return false;
}
// Pass MenuShortcut on to child menus.
int nmenus = getMenuCount();
for (int i = 0 ; i < nmenus ; i++) {
Menu m = getMenu(i);
if (m.handleShortcut(e)) {
return true;
}
}
return false;
}
示例4: processInterruption
/**
* Prevents showing a popup if a user releases the <code>releaseKey</code>
* in time specified by <code>invokerTimer</code> (which is 200ms by
* default).
*/
private static void processInterruption(KeyEvent kev) {
int keyCode = kev.getKeyCode();
if (keyCode == releaseKey && kev.getID() == KeyEvent.KEY_RELEASED) {
// if an user releases Ctrl-Tab before the time to show
// popup expires, don't show the popup at all and switch to
// the last used document immediately
cleanupInterrupter();
hits = 0;
AbstractAction rva = new ThreadsHistoryAction();
rva.actionPerformed(new ActionEvent(kev.getSource(),
ActionEvent.ACTION_PERFORMED,
"immediately", kev.getModifiers())); // NOI18N
kev.consume();
// #88931: Need to react to KEY_PRESSED, not KEY_RELEASED, to not miss the hit
} else if (keyCode == triggerKey
&& kev.getModifiers() == InputEvent.CTRL_MASK
&& kev.getID() == KeyEvent.KEY_PRESSED) {
// count number of trigger key hits before popup is shown
hits++;
kev.consume();
cleanupInterrupter();
instance = new KeyboardPopupSwitcher(hits + 1, true);
instance.showPopup();
}
}
示例5: handleShortcut
boolean handleShortcut(KeyEvent e) {
// Is it a key event?
int id = e.getID();
if (id != KeyEvent.KEY_PRESSED && id != KeyEvent.KEY_RELEASED) {
return false;
}
// Is the accelerator modifier key pressed?
int accelKey = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
if ((e.getModifiers() & accelKey) == 0) {
return false;
}
// Pass MenuShortcut on to child menus.
int nmenus = getMenuCount();
for (int i = 0 ; i < nmenus ; i++) {
Menu m = getMenu(i);
if (m.handleShortcut(e)) {
return true;
}
}
return false;
}
示例6: processKeyEvent
/**
* Forwards key events directly to the input handler. This is slightly faster than using a
* KeyListener because some Swing overhead is avoided.
*/
@Override
public void processKeyEvent(KeyEvent evt) {
if (inputHandler == null) {
return;
}
switch (evt.getID()) {
case KeyEvent.KEY_TYPED:
inputHandler.keyTyped(evt);
break;
case KeyEvent.KEY_PRESSED:
inputHandler.keyPressed(evt);
break;
case KeyEvent.KEY_RELEASED:
inputHandler.keyReleased(evt);
break;
}
}
示例7: 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;
}
示例8: dispatchKeyEvent
@Override
public boolean dispatchKeyEvent(KeyEvent e) {
switch (e.getID()) {
case KeyEvent.KEY_PRESSED:
//Do nothing
break;
case KeyEvent.KEY_RELEASED:
if(e.getKeyCode() == KeyEvent.VK_ESCAPE){
guiInput.interruptThreads(true);
guiInput.cancel(true); //Stop analysis thread
IJ.showProgress(0); //Reset progress bar
if(isGUI){
guiOKButton.setText("OK");
guiFrame.pack();
}
analysisStarted = false;
IJ.showStatus("Analysis cancelled..."); //Update IJ status
guiInput = new Hough_Circle(); //Create new instance of analysis worker, since last worker thread was cancelled
}
break;
case KeyEvent.KEY_TYPED:
//Do nothing
break;
default:
break;
}
return false;
}
示例9: getKeyEventType
/**
* Returns the type of <code>KeyEvent</code> which corresponds to
* this <code>AWTKeyStroke</code>.
*
* @return <code>KeyEvent.KEY_PRESSED</code>,
* <code>KeyEvent.KEY_TYPED</code>,
* or <code>KeyEvent.KEY_RELEASED</code>
* @see java.awt.event.KeyEvent
*/
public final int getKeyEventType() {
if (keyCode == KeyEvent.VK_UNDEFINED) {
return KeyEvent.KEY_TYPED;
} else {
return (onKeyRelease)
? KeyEvent.KEY_RELEASED
: KeyEvent.KEY_PRESSED;
}
}
示例10: handleJavaKeyEvent
@Override
public boolean handleJavaKeyEvent(KeyEvent e) {
switch (e.getID()) {
case KeyEvent.KEY_RELEASED:
if (e.getKeyCode() == KeyEvent.VK_SPACE){
handleAction(e.getWhen(), e.getModifiers());
}
break;
}
return false;
}
示例11: dispatchKeyEvent
@Override
public boolean dispatchKeyEvent(KeyEvent e) {
if (e.getID() == KeyEvent.KEY_PRESSED) {
keyPressed(e);
} else if (e.getID() == KeyEvent.KEY_RELEASED) {
keyReleased(e);
} else if (e.getID() == KeyEvent.KEY_TYPED) {
keyTyped(e);
}
return false;
}
示例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);
}
}
示例13: handleJavaKeyEvent
void handleJavaKeyEvent(KeyEvent e) {
int id = e.getID();
switch (id) {
case KeyEvent.KEY_PRESSED:
if (e.getKeyCode() == KeyEvent.VK_SPACE)
{
pressed=true;
armed=true;
repaint();
action(e.getWhen(),e.getModifiers());
}
break;
case KeyEvent.KEY_RELEASED:
if (e.getKeyCode() == KeyEvent.VK_SPACE)
{
pressed = false;
armed = false;
repaint();
}
break;
}
}
示例14: handleJavaKeyEvent
void handleJavaKeyEvent(KeyEvent e) {
int id = e.getID();
switch (id) {
case KeyEvent.KEY_PRESSED:
if (e.getKeyCode() == KeyEvent.VK_SPACE)
{
pressed=true;
armed=true;
repaint();
@SuppressWarnings("deprecation")
final int modifiers = e.getModifiers();
action(e.getWhen(), modifiers);
}
break;
case KeyEvent.KEY_RELEASED:
if (e.getKeyCode() == KeyEvent.VK_SPACE)
{
pressed = false;
armed = false;
repaint();
}
break;
}
}
示例15: updateKeyStates
/**
* Helper method that keeps track of the pressed special keys (space, meta
* and alt key).
*
* @param keyEvent The key event to analyze.
*/
private void updateKeyStates(KeyEvent keyEvent) {
// update spaceKeyDown
if (keyEvent.getKeyCode() == KeyEvent.VK_SPACE) {
if (keyEvent.getID() == KeyEvent.KEY_RELEASED) {
spaceKeyDown = false;
} else if (keyEvent.getID() == KeyEvent.KEY_PRESSED) {
spaceKeyDown = true;
}
}
// update metaKeyDown
if (keyEvent.getKeyCode() == KeyEvent.VK_META) {
if (keyEvent.getID() == KeyEvent.KEY_RELEASED) {
metaKeyDown = false;
} else if (keyEvent.getID() == KeyEvent.KEY_PRESSED) {
metaKeyDown = true;
}
}
// update altKeyDown
if (keyEvent.getKeyCode() == KeyEvent.VK_ALT) {
if (keyEvent.getID() == KeyEvent.KEY_RELEASED) {
altKeyDown = false;
} else if (keyEvent.getID() == KeyEvent.KEY_PRESSED) {
altKeyDown = true;
}
}
}