예제 #1
0
  @Override
  public void keyPressed(KeyEvent e) {
    // TODO Auto-generated method stub
    if (e.getKeyCode() == KeyEvent.VK_W) {
      this.hero.setDirection(0);
      hero.moveUp();
    } else if (e.getKeyCode() == KeyEvent.VK_D) {
      this.hero.setDirection(1);
      hero.moveRight();
    } else if (e.getKeyCode() == KeyEvent.VK_S) {
      this.hero.setDirection(2);
      hero.moveDown();
    } else if (e.getKeyCode() == KeyEvent.VK_A) {
      this.hero.setDirection(3);
      hero.moveLeft();
    }
    // 判断玩家是否按下J键 则开火
    if (e.getKeyCode() == KeyEvent.VK_J) {
      if (this.hero.bombs.size() <= 40) {

        hero.fire();
      }
    }
    this.repaint();
  }
예제 #2
0
  public void keyTyped(KeyEvent e) {
    if (!enabled) return;
    TextComponent input = (TextComponent) e.getSource();
    String strContent = input.getText();

    char c = e.getKeyChar();
    if (!isModifier(c)) return;
    int pos = input.getCaretPosition();
    if (pos <= 0) return;
    int idx = pos - 1; // position of the character to be modified
    char last = strContent.charAt(idx);
    char newVal = last;
    if (isCircumflex(c, last)) newVal = encoding.addCircumflex(last);
    else if (isBreve(c, last)) newVal = encoding.addBreveHorn(last);
    else if (isHorn(c, last)) newVal = encoding.addBreveHorn(last);
    else if (isStroke(c, last)) newVal = encoding.addStroke(last);
    else if (isToneMark(c)) {
      idx = indexOfToneCarrier(pos, strContent);
      if (idx < 0) return;
      last = strContent.charAt(idx);
      newVal = encoding.modifyTone(last, getToneMarkId(c));
    }
    if (last != newVal) {
      input.setCaretPosition(idx);
      TextField txt;
      //			input.moveCaretPosition(idx+1);
      //			input.replaceSelection("" + newVal);
      input.setCaretPosition(pos);
      e.consume();
    }
  }
예제 #3
0
    @Override
    public void keyPressed(KeyEvent evt) {
      switch (evt.getKeyCode()) {
        case KeyEvent.VK_SPACE:
          goToSelectedNode(M_OPEN);

          // f**k me dead
          EventQueue.invokeLater(
              new Runnable() {
                @Override
                public void run() {
                  resultTree.requestFocus();
                }
              });

          evt.consume();
          break;
        case KeyEvent.VK_ENTER:
          goToSelectedNode(M_OPEN);
          evt.consume();
          break;
        case KeyEvent.VK_DELETE:
          removeSelectedNode();
          evt.consume();
          break;
        default:
          break;
      }
    }
예제 #4
0
 void dispatch() {
   synchronized (events) {
     if (mousemv != null) {
       mousepos = new Coord(mousemv.getX(), mousemv.getY());
       ui.mousemove(mousemv, mousepos);
       mousemv = null;
     }
     InputEvent e = null;
     while ((e = events.poll()) != null) {
       if (e instanceof MouseEvent) {
         MouseEvent me = (MouseEvent) e;
         if (me.getID() == MouseEvent.MOUSE_PRESSED) {
           ui.mousedown(me, new Coord(me.getX(), me.getY()), me.getButton());
         } else if (me.getID() == MouseEvent.MOUSE_RELEASED) {
           ui.mouseup(me, new Coord(me.getX(), me.getY()), me.getButton());
         } else if (me instanceof MouseWheelEvent) {
           ui.mousewheel(
               me, new Coord(me.getX(), me.getY()), ((MouseWheelEvent) me).getWheelRotation());
         }
       } else if (e instanceof KeyEvent) {
         KeyEvent ke = (KeyEvent) e;
         if (ke.getID() == KeyEvent.KEY_PRESSED) {
           ui.keydown(ke);
         } else if (ke.getID() == KeyEvent.KEY_RELEASED) {
           ui.keyup(ke);
         } else if (ke.getID() == KeyEvent.KEY_TYPED) {
           ui.type(ke);
         }
       }
       ui.lastevent = System.currentTimeMillis();
     }
   }
 }
  /**
   * Method declaration
   *
   * @param k
   */
  public void keyTyped(KeyEvent k) {

    if (k.getKeyChar() == '\n' && k.isControlDown()) {
      k.consume();
      execute();
    }
  }
예제 #6
0
  @Override
  public void keyTyped(final KeyEvent e) {
    if (undo == null || control(e) || DELNEXT.is(e) || DELPREV.is(e) || ESCAPE.is(e)) return;

    text.pos(text.cursor());
    // string to be added
    String ch = String.valueOf(e.getKeyChar());

    // remember if marked text is to be deleted
    boolean del = true;
    final byte[] txt = text.text();
    if (TAB.is(e)) {
      if (text.marked()) {
        // check if lines are to be indented
        final int s = Math.min(text.pos(), text.start());
        final int l = Math.max(text.pos(), text.start()) - 1;
        for (int p = s; p <= l && p < txt.length; p++) del &= txt[p] != '\n';
        if (!del) {
          text.indent(s, l, e.isShiftDown());
          ch = null;
        }
      } else {
        boolean c = true;
        for (int p = text.pos() - 1; p >= 0 && c; p--) {
          final byte b = txt[p];
          c = ws(b);
          if (b == '\n') break;
        }
        if (c) ch = "  ";
      }
    }

    // delete marked text
    if (text.marked() && del) text.delete();

    if (ENTER.is(e)) {
      // adopt indentation from previous line
      final StringBuilder sb = new StringBuilder(1).append(e.getKeyChar());
      int s = 0;
      for (int p = text.pos() - 1; p >= 0; p--) {
        final byte b = txt[p];
        if (b == '\n') break;
        if (b == '\t') {
          s += 2;
        } else if (b == ' ') {
          s++;
        } else {
          s = 0;
        }
      }
      for (int p = 0; p < s; p++) sb.append(' ');
      ch = sb.toString();
    }

    if (ch != null) text.add(ch);
    text.setCaret();
    rend.calc();
    showCursor(2);
    e.consume();
  }
예제 #7
0
 @FXML
 void playTrackFromKeyboard(KeyEvent e) {
   if (e.getCode() == KeyCode.ENTER) {
     playSelectedTrack();
     e.consume();
   }
 }
  @SuppressWarnings("HardCodedStringLiteral")
  private boolean togglePopup(KeyEvent e) {
    final KeyStroke stroke = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers());
    final Object action = ((InputMap) UIManager.get("ComboBox.ancestorInputMap")).get(stroke);
    if ("selectNext".equals(action)) {
      if (!isPopupShowing()) {
        return true;
      } else {
        return false;
      }
    } else if ("togglePopup".equals(action)) {
      if (isPopupShowing()) {
        closePopup();
      } else {
        suggestCompletion(true, true);
      }
      return true;
    } else {
      final Keymap active = KeymapManager.getInstance().getActiveKeymap();
      final String[] ids = active.getActionIds(stroke);
      if (ids.length > 0 && IdeActions.ACTION_CODE_COMPLETION.equals(ids[0])) {
        suggestCompletion(true, true);
      }
    }

    return false;
  }
예제 #9
0
    public void keyPressed(KeyEvent e) {
      int keyCode = e.getKeyCode();

      System.out.println(keyCode + ", " + e.getKeyChar()); // testing

      // When shift is held, the user has entered editing mode
      if (e.isShiftDown()) {
        editingMode = true;
      } else {
        editingMode = false;
      }

      if (keyCode == KeyEvent.VK_SPACE)
        // Stop all stoppable sounds
        soundManager.stopSounds();
      else {
        SoundInfo sound = soundManager.getSound(keyCode);
        if (sound != null) {
          // Play, stop, or edit the sound
          dialogManager.handleSoundEvent(sound);
        } else if (getEditingMode()
            && keyCode != KeyEvent.VK_SHIFT
            && keyCode != KeyEvent.VK_CAPS_LOCK) {
          // Create a new sound
          dialogManager.displayNewSoundDialog();
        }
      }
    }
예제 #10
0
  @Override
  public void keyTyped(final KeyEvent e) {
    if (!hist.active()
        || control(e)
        || DELNEXT.is(e)
        || DELPREV.is(e)
        || ESCAPE.is(e)
        || CUT2.is(e)) return;

    final int caret = editor.pos();

    // remember if marked text is to be deleted
    final StringBuilder sb = new StringBuilder(1).append(e.getKeyChar());
    final boolean indent = TAB.is(e) && editor.indent(sb, e.isShiftDown());

    // delete marked text
    final boolean selected = editor.selected() && !indent;
    if (selected) editor.delete();

    final int move = ENTER.is(e) ? editor.enter(sb) : editor.add(sb, selected);

    // refresh history and adjust cursor position
    hist.store(editor.text(), caret, editor.pos());
    if (move != 0) editor.pos(Math.min(editor.size(), caret + move));

    // adjust text height
    scrollCode.invokeLater(true);
    e.consume();
  }
 @Override
 public void keyPressed(KeyEvent e) {
   TreePath path = myTree.getLeadSelectionPath();
   if (path == null) return;
   final Object lastComponent = path.getLastPathComponent();
   if (e.getKeyCode() == KeyEvent.VK_ENTER) {
     if (lastComponent instanceof ParentNode) return;
     doOKAction();
     e.consume();
   } else if (e.getKeyCode() == KeyEvent.VK_INSERT) {
     if (lastComponent instanceof ElementNode) {
       final DefaultMutableTreeNode node = (DefaultMutableTreeNode) lastComponent;
       if (!mySelectedNodes.contains(node)) {
         if (node.getNextNode() != null) {
           myTree.setSelectionPath(new TreePath(node.getNextNode().getPath()));
         }
       } else {
         if (node.getNextNode() != null) {
           myTree.removeSelectionPath(new TreePath(node.getPath()));
           myTree.setSelectionPath(new TreePath(node.getNextNode().getPath()));
           myTree.repaint();
         }
       }
       e.consume();
     }
   }
 }
예제 #12
0
 /**
  * Event handler helper-method. Actionable F2-key check
  *
  * @param evt User Keyboard Press
  */
 private void checkF2Key(KeyEvent evt) {
   if (evt.getKeyCode() == 113) {
     System.out.println(evt.getKeyCode());
     EasyButtonMouseReleased(null);
     // HardButtonMouseReleased(null);
     // FileMenuMouseClicked(null);
   }
 }
예제 #13
0
public void keyPressed( KeyEvent e )
    {
      if (readonly)
	return;
      if (e.getKeyChar() == '\033')
	Abort ();
      else if (e.getKeyChar() == 'l')
	Layout (null);
    }
예제 #14
0
 public void keyReleased(KeyEvent ke) {
   if (ke.getKeyCode() == KeyEvent.VK_UP) {
     String up = history.getUp();
     if (up != null) messageText.setText(up);
   } else if (ke.getKeyCode() == KeyEvent.VK_DOWN) {
     String down = history.getDown();
     if (down != null) messageText.setText(down);
   }
 }
예제 #15
0
	/**
	 * If a key is being grabbed, this method should be called with
	 * the appropriate key event. It executes the grab action with
	 * the typed character as the parameter.
	 */
	protected void handleGrabAction(KeyEvent evt)
	{
		// Clear it *before* it is executed so that executeAction()
		// resets the repeat count
		ActionListener _grabAction = grabAction;
		grabAction = null;
		executeAction(_grabAction,evt.getSource(),
			String.valueOf(evt.getKeyChar()));
	}
 public void keyPressed(KeyEvent e) {
   if (e.getKeyCode() == KeyEvent.VK_UP) {
     y1Rise++;
     if (y1Rise >= 20) y1Rise = 20;
   } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
     y1Rise--;
     if (y1Rise >= 20) y1Rise = 20;
   }
 }
예제 #17
0
 public void keyReleased(KeyEvent e) {
   int keyCode = e.getKeyCode();
   IJ.setKeyUp(keyCode);
   int flags = e.getModifiers();
   boolean control = (flags & KeyEvent.CTRL_MASK) != 0;
   boolean meta = (flags & KeyEvent.META_MASK) != 0;
   boolean shift = (flags & e.SHIFT_MASK) != 0;
   if (keyCode == KeyEvent.VK_G && shift && (control || meta)) new ScreenGrabber().run("");
 }
예제 #18
0
 /**
  * ************************************************
  *
  * <pre>
  * Summary: Catch any key pressed.
  *
  * </pre>
  *
  * *************************************************
  */
 public void keyPressed(KeyEvent e) {
   // Have an escape do the same as clicking cancel.
   if (e.getKeyCode() == KeyEvent.VK_ESCAPE) abandonButton.doClick();
   // Return
   else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
     if (closeButton.isEnabled()) {
       closeButton.doClick();
     }
   }
 }
예제 #19
0
 /**
  * Event handler method. Frame checks for user keyboard presses
  *
  * @param evt User Keyboard Press
  */
 private void formKeyPressed(KeyEvent evt) {
   // TODO add your handling code here:
   checkF2Key(evt);
   // checkTestCMD(evt);
   System.out.println(
       "Form detected a key press: "
           + evt.getKeyLocation()
           + ": "
           + evt.getKeyCode()
           + " - "
           + evt.getKeyChar());
 }
  @Override
  public void keyPressed(KeyEvent evt) {
    multicaster.keyPressed(evt);
    if (!evt.isConsumed()) {
      super.keyPressed(evt);

      // Forward key presses to the handler
      if (dragLocation != null) {
        multicaster.trackStep(anchor, dragLocation, evt.getModifiersEx(), getView());
      }
    }
  }
예제 #21
0
    public void keyPressed(KeyEvent ke) {

      if (ke.getKeyCode() == ke.VK_TAB) {
        int x = ((JTable) ke.getSource()).getSelectedColumn();
        int y = ((JTable) ke.getSource()).getSelectedRow();
        int maxX = ((JTable) ke.getSource()).getColumnCount();
        int maxY = ((JTable) ke.getSource()).getRowCount();
        TableModel tm = ((JTable) ke.getSource()).getModel();
        if (x == maxX - 1 && y == maxY - 1) {
          ((DefaultTableModel) tm).addRow(new Object[maxX]);
        }
      }
    }
예제 #22
0
 public void keyPressed(KeyEvent e) {
   if (this.pan.getGameState() != null && this.pan.getGameState()) {
     if (e.getKeyCode() == KeyEvent.VK_UP) {
       // this.pan.moveUp();
     }
     if (e.getKeyCode() == KeyEvent.VK_DOWN) {
       // this.pan.moveDown();
     }
     if (e.getKeyCode() == KeyEvent.VK_LEFT) {
       this.pan.moveLeft();
     }
     if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
       this.pan.moveRight();
     }
     if (e.getKeyCode() == KeyEvent.VK_A) {
       this.pan.rCCW();
     }
     if (e.getKeyCode() == KeyEvent.VK_D) {
       this.pan.rCW();
     }
     if (e.getKeyCode() == KeyEvent.VK_SPACE) { // set piece in place
       this.pan.placeElectromino();
     }
     if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
       this.pan.setMenuState(new Boolean(true));
       this.pan.setGameState(new Boolean(false));
     }
   }
 }
  /**
   * Treat escape key events. Stop drawing the rectangle and revert to the previous state, without
   * doing anything. The event can be consumed (return true) or be delegated to other listeners
   * (return false).
   *
   * @param keyEvent The new key event.
   * @return True if the key event has been consumed, false otherwise.
   */
  public boolean keyEvent(KeyEvent keyEvent) {
    final boolean keyReleased = keyEvent.getID() == KeyEvent.KEY_RELEASED;
    final boolean isEscapeKey = keyEvent.getKeyCode() == KeyEvent.VK_ESCAPE;

    if (keyReleased && isEscapeKey) {
      dragStartPos = null;
      dragCurrentPos = null;
      releaseBackground();
      mapComponent.repaint();
      setDefaultCursor();
      reportClearDistance();
    }

    return false;
  }
예제 #24
0
  // For KeyEvents that invole keys being pressed
  public void keyPressed(KeyEvent event) {
    // Assigns the keyPressed array at event.getKeyCode() to true as the key has been pressed
    keyPressed[event.getKeyCode()] = true;

    // Calls the update positions method to update the positions of the sprites.
    updatePositions();
  }
 @Override
 public boolean dispatchKeyEvent(KeyEvent e) {
   int code = e.getKeyCode();
   int modifiers = e.getModifiers();
   if (code == KeyEvent.VK_ESCAPE) {
     if (isShowingSheet()) {
       discardTopSheet();
       return true;
     }
   }
   if (code == KeyEvent.VK_Q && modifiers == Platform.getPlatform().getCommandModifierMask()) {
     shutdown();
     return true;
   }
   return false;
 }
 @Override
 public void keyReleased(KeyEvent evt) {
   multicaster.keyReleased(evt);
   // Forward key releases to the handler
   if (dragLocation != null) {
     multicaster.trackStep(anchor, dragLocation, evt.getModifiersEx(), getView());
   }
 }
예제 #27
0
 public void keyPressed(KeyEvent e) {
   int keyCode = e.getKeyCode();
   IJ.setKeyDown(keyCode);
   if (keyCode == KeyEvent.VK_ENTER && textArea1 == null && okay != null && okay.isEnabled()) {
     wasOKed = true;
     if (IJ.isMacOSX()) accessTextFields();
     dispose();
   } else if (keyCode == KeyEvent.VK_ESCAPE) {
     wasCanceled = true;
     dispose();
     IJ.resetEscape();
   } else if (keyCode == KeyEvent.VK_W
       && (e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0) {
     wasCanceled = true;
     dispose();
   }
 }
예제 #28
0
 public void keyReleased(KeyEvent evt) {
   keys[evt.getKeyCode()] = false;
   // reset the counters for for the sprite s
   player1.resetCounter();
   if (!player1.getPower().equals("Balloon")) {
     player1.resetPicCounter();
   }
 }
예제 #29
0
 static void handleKeyTyped(KeyEvent e) {
   if (e.getKeyChar() == ' ') {
     currentSequenceNumDisplay++;
     scribbles = Collections.synchronizedList(new ArrayList<DrawObject>());
     currentScribbleNum = 0;
   }
   drawArea.repaint();
 }
예제 #30
0
 @Override
 public void keyPressed(KeyEvent e) {
   // Accept "copy" key strokes
   KeyStroke ks = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers());
   JComponent comp = (JComponent) e.getSource();
   for (int i = 0; i < 3; i++) {
     InputMap im = comp.getInputMap(i);
     Object key = im.get(ks);
     if (defaultEditorKitCopyActionName.equals(key)
         || transferHandlerCopyActionName.equals(key)) {
       return;
     }
   }
   // Accept JTable navigation key strokes
   if (!tableNavigationKeys.contains(e.getKeyCode())) {
     e.consume();
   }
 }