示例#1
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();
  }
示例#2
0
  /** This method cannot be called directly. */
  public void keyTyped(KeyEvent e) {
    int keyCode = e.getKeyCode();
    System.out.println(keyCode);
    switch (keyCode) {
      case KeyEvent.VK_W:
        // handle up
        System.out.println("up?");
        break;
      case KeyEvent.VK_DOWN:
        // handle down
        break;
      case KeyEvent.VK_LEFT:
        // handle left
        break;
      case KeyEvent.VK_RIGHT:
        // handle right
        break;
    }
    System.out.println(e.getKeyChar());
    if (e.getKeyChar() == KeyEvent.VK_UP) {
      System.out.println("up arrow pressed");
    }

    synchronized (keyLock) {
      keysTyped.addFirst(e.getKeyChar());
    }
  }
示例#3
0
public void keyPressed( KeyEvent e )
    {
      if (readonly)
	return;
      if (e.getKeyChar() == '\033')
	Abort ();
      else if (e.getKeyChar() == 'l')
	Layout (null);
    }
  public void keyTyped(KeyEvent event) {
    char key = event.getKeyChar();

    System.out.println("keyTyped " + event.getKeyCode());

    if (key == KeyEvent.VK_BACK_SPACE) {
      if (msg2.length() > 0) {
        msg2 = msg2.substring(0, msg2.length() - 1);
      }
    } else if (key >= KeyEvent.VK_SPACE) {
      if (msg2.length() < 40) {
        msg2 += event.getKeyChar();
      }
    }
    repaint();
  }
 public void keyPressed(KeyEvent event) {
   msg1 = "";
   System.out.println("keyPressed " + event.getKeyCode());
   if (event.getKeyChar() == KeyEvent.CHAR_UNDEFINED) {
     int key = event.getKeyCode();
     // Funktionstaste abfragen
     if (key == KeyEvent.VK_F1) {
       msg1 = "F1";
     } else if (key == KeyEvent.VK_F2) {
       msg1 = "F2";
     } else if (key == KeyEvent.VK_F3) {
       msg1 = "F3";
     }
     // Modifier abfragen
     if (msg1.length() > 0) {
       if (event.isAltDown()) {
         msg1 = "ALT + " + msg1;
       }
       if (event.isControlDown()) {
         msg1 = "STRG + " + msg1;
       }
       if (event.isShiftDown()) {
         msg1 = "UMSCHALT + " + msg1;
       }
     }
   }
   repaint();
 }
 void jTextFieldSendMessages_keyPressed(KeyEvent e) {
   if (e.getKeyCode() == e.VK_DOWN) {
     String s = msgHistory.forward();
     if (s != null) {
       jTextFieldSendMessages.setText(s);
     }
   } else if (e.getKeyCode() == e.VK_UP) {
     String s = msgHistory.back();
     if (s != null) {
       jTextFieldSendMessages.setText(s);
     }
   } else if (e.getKeyChar() == '\n') {
     String body = jTextFieldSendMessages.getText();
     if (body.length() > 0) {
       if (body.charAt(body.length() - 1) == '\n') body = body.substring(0, body.length() - 1);
       String subject = jTextFieldSendSubject.getText();
       if (subject.length() > 0) {
         if (subject.charAt(subject.length() - 1) == '\n')
           subject = subject.substring(0, subject.length() - 1);
       }
       if (session != null && session.isConnected()) {
         session.postMessage(jTextFieldTargetUser.getText(), subject, body);
         displaySendMessage(subject, jTextFieldTargetUser.getText(), body, outgoingMsgAttrSet);
       }
       msgHistory.add(body);
       subjectHistory.add(subject);
       subjectHistory.reset();
       msgHistory.reset();
       jTextFieldSendMessages.setText("");
       jTextFieldSendSubject.setText("");
     }
   }
 }
示例#7
0
 public void keyPressed(KeyEvent key) {
   switch (key.getKeyChar()) {
     case KeyEvent.VK_ESCAPE:
       System.exit(0);
       break;
   }
 }
示例#8
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();
    }
  }
    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();
        }
      }
    }
  @Override
  public void keyPressed(final KeyEvent e) {
    if (!(e.isAltDown() || e.isMetaDown() || e.isControlDown() || myPanel.isNodePopupActive())) {
      if (!Character.isLetter(e.getKeyChar())) {
        return;
      }

      final IdeFocusManager focusManager = IdeFocusManager.getInstance(myPanel.getProject());
      final ActionCallback firstCharTyped = new ActionCallback();
      focusManager.typeAheadUntil(firstCharTyped);
      myPanel.moveDown();
      //noinspection SSBasedInspection
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              try {
                final Robot robot = new Robot();
                final boolean shiftOn = e.isShiftDown();
                final int code = e.getKeyCode();
                if (shiftOn) {
                  robot.keyPress(KeyEvent.VK_SHIFT);
                }
                robot.keyPress(code);
                robot.keyRelease(code);

                // don't release Shift
                firstCharTyped.setDone();
              } catch (AWTException ignored) {
              }
            }
          });
    }
  }
示例#11
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();
  }
  /**
   * Method declaration
   *
   * @param k
   */
  public void keyTyped(KeyEvent k) {

    if (k.getKeyChar() == '\n' && k.isControlDown()) {
      k.consume();
      execute();
    }
  }
示例#13
0
 protected void processKeyEvent(final KeyEvent e) {
   int id = e.getID();
   switch (id) {
     case KeyEvent.KEY_TYPED:
       KeyEventCZ loKey = new KeyEventCZ(e.getKeyChar());
       moTipo.getTecla(super.getText(), loKey);
       e.setKeyChar(loKey.getKeyChar());
       break;
     case KeyEvent.KEY_PRESSED:
       if (e.getKeyCode() == e.VK_ENTER) {
         e.setKeyCode(0);
         transferFocus();
       }
       if (e.getKeyCode() == e.VK_ESCAPE) {
         e.setKeyCode(0);
         moTipo.restaurarTexto();
         super.setText(moTipo.getText());
       }
       break;
     case KeyEvent.KEY_RELEASED:
       break;
     default:
   }
   super.processKeyEvent(e);
 }
示例#14
0
 /** Kickstart auto-complete suggestions */
 private void prepareSuggestions(final KeyEvent evt) {
   // Provide completions only if it's enabled
   if (JavaMode.codeCompletionsEnabled
       && (JavaMode.ccTriggerEnabled || (suggestion != null && suggestion.isVisible()))) {
     Messages.log("[KeyEvent]" + evt.getKeyChar() + "  |Prediction started");
     fetchPhrase();
   }
 }
示例#15
0
 static void handleKeyTyped(KeyEvent e) {
   if (e.getKeyChar() == ' ') {
     currentSequenceNumDisplay++;
     scribbles = Collections.synchronizedList(new ArrayList<DrawObject>());
     currentScribbleNum = 0;
   }
   drawArea.repaint();
 }
示例#16
0
 @Override
 public void keyPressed(KeyEvent event) {
   char key = event.getKeyChar();
   if (key == 'k') {
     player.move(0, playerspeed);
   } else if (key == 'i') {
     player.move(0, -playerspeed);
   }
 }
示例#17
0
    public void processKeyEvent(KeyEvent evt) {
      evt = KeyEventWorkaround.processKeyEvent(evt);
      if (evt == null) return;

      switch (evt.getID()) {
        case KeyEvent.KEY_TYPED:
          char ch = evt.getKeyChar();
          if (!nonDigit && Character.isDigit(ch)) {
            super.processKeyEvent(evt);
            repeat = true;
            repeatCount = Integer.parseInt(action.getText());
          } else {
            nonDigit = true;
            if (repeat) {
              passToView(evt);
            } else super.processKeyEvent(evt);
          }
          break;
        case KeyEvent.KEY_PRESSED:
          int keyCode = evt.getKeyCode();
          if (evt.isActionKey()
              || evt.isControlDown()
              || evt.isAltDown()
              || evt.isMetaDown()
              || keyCode == KeyEvent.VK_BACK_SPACE
              || keyCode == KeyEvent.VK_DELETE
              || keyCode == KeyEvent.VK_ENTER
              || keyCode == KeyEvent.VK_TAB
              || keyCode == KeyEvent.VK_ESCAPE) {
            nonDigit = true;
            if (repeat) {
              passToView(evt);
              break;
            } else if (keyCode == KeyEvent.VK_TAB) {
              complete(true);
              evt.consume();
            } else if (keyCode == KeyEvent.VK_ESCAPE) {
              evt.consume();
              if (popup != null) {
                popup.dispose();
                popup = null;
                action.requestFocus();
              } else {
                if (temp) view.removeToolBar(ActionBar.this);
                view.getEditPane().focusOnTextArea();
              }
              break;
            } else if ((keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_DOWN)
                && popup != null) {
              popup.list.processKeyEvent(evt);
              break;
            }
          }
          super.processKeyEvent(evt);
          break;
      }
    }
示例#18
0
  private void processCompletionKeys(final KeyEvent event) {
    char keyChar = event.getKeyChar();
    int keyCode = event.getKeyCode();
    if (keyChar == KeyEvent.VK_ENTER
        || keyChar == KeyEvent.VK_ESCAPE
        || keyChar == KeyEvent.VK_TAB
        || (event.getID() == KeyEvent.KEY_RELEASED
            && keyCode != KeyEvent.VK_LEFT
            && keyCode != KeyEvent.VK_RIGHT)) {
      // ignore
    } else if (keyChar == ')') {
      // https://github.com/processing/processing/issues/2741
      hideSuggestion();

    } else if (keyChar == '.') {
      if (JavaMode.codeCompletionsEnabled) {
        Messages.log(
            "[KeyEvent]" + KeyEvent.getKeyText(event.getKeyCode()) + "  |Prediction started");
        fetchPhrase();
      }
    } else if (keyChar == ' ') { // Trigger on Ctrl-Space
      if (!Platform.isMacOS()
          && JavaMode.codeCompletionsEnabled
          && (event.isControlDown() || event.isMetaDown())) {
        // Provide completions only if it's enabled
        if (JavaMode.codeCompletionsEnabled) {
          // Removed for https://github.com/processing/processing/issues/3847
          // try {
          //  getDocument().remove(getCaretPosition() - 1, 1); // Remove the typed space
          Messages.log("[KeyEvent]" + event.getKeyChar() + "  |Prediction started");
          fetchPhrase();
          // } catch (BadLocationException e) {
          //  e.printStackTrace();
          // }
        }
      } else {
        hideSuggestion(); // hide on spacebar
      }
    } else {
      if (JavaMode.codeCompletionsEnabled) {
        prepareSuggestions(event);
      }
    }
  }
示例#19
0
  public void keyTyped(KeyEvent e) {
    char key = e.getKeyChar();

    if (state.equals("regular") && key == 'a') {
      stringToAdd = "";
      state = "add";
    } else if (state.equals("add") && (' ' <= key && key <= '~')) {
      stringToAdd += key;
    }
  }
示例#20
0
  public void keyPressed(KeyEvent e) {
    char keycode = e.getKeyChar();
    System.out.println(keycode);
    // f.add(new Button("button"),BorderLayout.SOUTH);
    // f.lb = new Label();
    f.lb.setText("You Click: " + keycode);
    // Frame f = (Frame)e.getSource();
    // f.add(f.lb,BorderLayout.CENTER);

  }
示例#21
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());
 }
示例#22
0
文件: HexEdit.java 项目: khyuna/hyun
 @Override
 public void keyTyped(KeyEvent e) {
   if (e.getKeyChar() == KeyEvent.VK_TAB || e.getKeyChar() == KeyEvent.VK_ENTER) return;
   int addr = getCursorAddress();
   if (addr > SICXE.MAX_ADDR) return;
   if (focusOnHex) {
     int val = Conversion.hexToInt(String.valueOf(e.getKeyChar()), -1);
     if (val == -1) return;
     int b = get(addr);
     if (b < 0) return;
     if (firstNibble) b = (b & 0x0F) | ((val & 0x0F) << 4);
     else b = (b & 0xF0) | (val & 0x0F);
     set(addr, b);
     firstNibble = !firstNibble;
     if (firstNibble) moveCursor(1, 0);
   } else {
     set(addr, e.getKeyChar());
     moveCursor(1, 0);
   }
   repaint();
 }
示例#23
0
 void jTextFieldSendSubject_keyPressed(KeyEvent e) {
   if (e.getKeyCode() == e.VK_DOWN) {
     String s = subjectHistory.forward();
     if (s != null) {
       jTextFieldSendSubject.setText(s);
     }
   } else if (e.getKeyCode() == e.VK_UP) {
     String s = subjectHistory.back();
     if (s != null) {
       jTextFieldSendSubject.setText(s);
     }
   } else if (e.getKeyChar() == '\n') {
     jTextFieldSendMessages.requestFocus();
   }
 }
  private void displayInfo(KeyEvent e, String keyStatus) {
    // Method copied from http://java.sun.com/docs/books/tutorial/uiswing/events/keylistener.html

    // You should only rely on the key char if the event
    // is a key typed event.
    int id = e.getID();
    String keyString;
    if (id == KeyEvent.KEY_TYPED) {
      char c = e.getKeyChar();
      keyString = "key character = '" + c + "'";
    } else {
      int keyCode = e.getKeyCode();
      keyString = "key code = " + keyCode + " (" + KeyEvent.getKeyText(keyCode) + ")";
    }

    int modifiersEx = e.getModifiersEx();
    String modString = "extended modifiers = " + modifiersEx;
    String tmpString = KeyEvent.getModifiersExText(modifiersEx);
    if (tmpString.length() > 0) {
      modString += " (" + tmpString + ")";
    } else {
      modString += " (no extended modifiers)";
    }

    String actionString = "action key? ";
    if (e.isActionKey()) {
      actionString += "YES";
    } else {
      actionString += "NO";
    }

    String locationString = "key location: ";
    int location = e.getKeyLocation();
    if (location == KeyEvent.KEY_LOCATION_STANDARD) {
      locationString += "standard";
    } else if (location == KeyEvent.KEY_LOCATION_LEFT) {
      locationString += "left";
    } else if (location == KeyEvent.KEY_LOCATION_RIGHT) {
      locationString += "right";
    } else if (location == KeyEvent.KEY_LOCATION_NUMPAD) {
      locationString += "numpad";
    } else { // (location == KeyEvent.KEY_LOCATION_UNKNOWN)
      locationString += "unknown";
    }

    // Added:
    System.out.println("Keypress: " + keyString);
  }
示例#25
0
  /**
   * Processes a key event forwarded from the <code>MenuSelectionManager</code> and changes the menu
   * selection, if necessary, by using <code>MenuSelectionManager</code>'s API.
   *
   * <p>Note: you do not have to forward the event to sub-components. This is done automatically by
   * the <code>MenuSelectionManager</code>.
   *
   * @param e a <code>KeyEvent</code>
   * @param path the <code>MenuElement</code> path array
   * @param manager the <code>MenuSelectionManager</code>
   */
  public void processKeyEvent(KeyEvent e, MenuElement path[], MenuSelectionManager manager) {
    MenuKeyEvent mke =
        new MenuKeyEvent(
            e.getComponent(),
            e.getID(),
            e.getWhen(),
            e.getModifiers(),
            e.getKeyCode(),
            e.getKeyChar(),
            path,
            manager);
    processMenuKeyEvent(mke);

    if (mke.isConsumed()) {
      e.consume();
    }
  }
示例#26
0
  public void keyReleased(KeyEvent e) {
    char ch = e.getKeyChar();
    if (ch == KeyEvent.CHAR_UNDEFINED || Character.isISOControl(ch)) return;
    int pos = m_editor.getCaretPosition();
    String str = m_editor.getText();
    if (str.length() == 0) return;

    for (int k = 0; k < m_comboBox.getItemCount(); k++) {
      String item = m_comboBox.getItemAt(k).toString();
      if (item.startsWith(str)) {
        m_editor.setText(item);
        m_editor.setCaretPosition(item.length());
        m_editor.moveCaretPosition(pos);
        m_comboBox.setSelectedItem(item);
        break;
      }
    }
  }
示例#27
0
 private void processTerminalKeyTyped(KeyEvent e) {
   final char keychar = e.getKeyChar();
   if ((keychar & 0xff00) != 0) {
     final char[] foo;
     if (mySettingsProvider.altSendsEscape() && (e.getModifiers() & InputEvent.ALT_MASK) != 0) {
       foo = new char[] {Ascii.ESC, keychar};
     } else {
       foo = new char[] {keychar};
     }
     try {
       myTerminalStarter.sendString(new String(foo));
       if (mySettingsProvider.scrollToBottomOnTyping()) {
         scrollToBottom();
       }
     } catch (final RuntimeException ex) {
       LOG.error("Error sending key to emulator", ex);
     }
   }
 }
示例#28
0
 public void keyTyped(KeyEvent e) {
   char keyChar = e.getKeyChar();
   int flags = e.getModifiers();
   if (IJ.debugMode)
     IJ.log(
         "keyTyped: char=\""
             + keyChar
             + "\" ("
             + (int) keyChar
             + "), flags= "
             + Integer.toHexString(flags)
             + " ("
             + KeyEvent.getKeyModifiersText(flags)
             + ")");
   if (keyChar == '\\' || keyChar == 171 || keyChar == 223) {
     if (((flags & Event.ALT_MASK) != 0)) doCommand("Animation Options...");
     else doCommand("Start Animation [\\]");
   }
 }
 public void keyPressed(KeyEvent evt) {
   if (evt.getKeyCode() == evt.VK_RIGHT) {
     charcounter++;
     if (charcounter >= charnames.size()) {
       charcounter = 0;
     }
     showing = readGlyph((String) charnames.get(charcounter));
   } else if (evt.getKeyCode() == evt.VK_LEFT) {
     charcounter--;
     if (charcounter < 0) {
       charcounter = charnames.size() - 1;
     }
     showing = readGlyph((String) charnames.get(charcounter));
   } else {
     char c = evt.getKeyChar();
     //	System.out.println("Got char: "+name);
     showing = readGlyph(FontSupport.stdNames[FontSupport.standardEncoding[(int) c & 0xff]]);
   }
   repaint();
 }
示例#30
0
  private void processTerminalKeyPressed(KeyEvent e) {
    try {
      final int keycode = e.getKeyCode();
      final char keychar = e.getKeyChar();

      // numLock does not change the code sent by keypad VK_DELETE
      // although it send the char '.'
      if (keycode == KeyEvent.VK_DELETE && keychar == '.') {
        myTerminalStarter.sendBytes(new byte[] {'.'});
        return;
      }
      // CTRL + Space is not handled in KeyEvent; handle it manually
      else if (keychar == ' ' && (e.getModifiers() & InputEvent.CTRL_MASK) != 0) {
        myTerminalStarter.sendBytes(new byte[] {Ascii.NUL});
        return;
      }

      final byte[] code = myTerminalStarter.getCode(keycode, e.getModifiers());
      if (code != null) {
        myTerminalStarter.sendBytes(code);
        if (mySettingsProvider.scrollToBottomOnTyping() && isCodeThatScrolls(keycode)) {
          scrollToBottom();
        }
      } else if ((keychar & 0xff00) == 0) {
        final byte[] obuffer;
        if (mySettingsProvider.altSendsEscape() && (e.getModifiers() & InputEvent.ALT_MASK) != 0) {
          obuffer = new byte[] {Ascii.ESC, (byte) keychar};
        } else {
          obuffer = new byte[] {(byte) keychar};
        }
        myTerminalStarter.sendBytes(obuffer);

        if (mySettingsProvider.scrollToBottomOnTyping()) {
          scrollToBottom();
        }
      }
    } catch (final Exception ex) {
      LOG.error("Error sending key to emulator", ex);
    }
  }