Example #1
0
 /**
  * Adding key support. up and down arrows can be used to scroll listbox or dropdownList,up and
  * down, use shift+up/down for faster scrolling, use alt+up/down to jump to the top or bottom.
  *
  * @exclude {@inheritDoc}
  */
 @ControlP5.Invisible
 public void keyEvent(final KeyEvent theEvent) {
   super.keyEvent(theEvent);
   float x = getAbsolutePosition().x;
   float y = getAbsolutePosition().y;
   boolean b =
       (getWindow().mouseX > x
           && getWindow().mouseX < (x + _myWidth)
           && getWindow().mouseY > (y - getBarHeight())
           && getWindow().mouseY < y + _myOriginalBackgroundHeight);
   if (b && isOpen()) {
     float step = (1.0f / (float) items.size());
     if (cp5.isShiftDown()) {
       step *= 10;
     } else if (cp5.isAltDown()) {
       step = 1;
     }
     if (theEvent.getAction() == KeyEvent.PRESSED) {
       switch (theEvent.getKeyCode()) {
         case (PApplet.UP):
           _myScrollbar.setValue(PApplet.constrain(_myScrollbar.getValue() + step, 0, 1));
           break;
         case (PApplet.DOWN):
           _myScrollbar.setValue(PApplet.constrain(_myScrollbar.getValue() - step, 0, 1));
           break;
       }
     }
   }
 }
Example #2
0
 public void keyEvent(KeyEvent e) {
   if (e.getAction() == KeyEvent.PRESS) {
     if (e.getKey() == ' ') {
       home();
       parent.redraw();
     }
   }
 }
Example #3
0
 public void keyEvent(final KeyEvent e) {
   switch (e.getKey()) {
     case KeyEvent.PRESS:
       if (e.getKeyCode() == keyCode) ctrlPressed = 1;
       break;
     case KeyEvent.RELEASE:
       if (e.getKeyCode() == keyCode) ctrlPressed = 0;
       break;
   }
 }
Example #4
0
 public void keyEvent(processing.event.KeyEvent e) {
   int evtID = e.getAction();
   if (evtID != processing.event.KeyEvent.PRESS) return;
   switch (e.getKeyCode()) {
     case KeyEvent.VK_SPACE:
       this.reset();
       break;
     default:
       break;
   }
 }
  public void keyEvent(KeyEvent keyEvent) {
    char key = keyEvent.getKey();
    int keyCode = keyEvent.getKeyCode();

    switch (keyEvent.getAction()) {
      case KeyEvent.PRESS:
        keyPressed(key, keyCode);
        break;
      case KeyEvent.RELEASE:
        keyReleased(key, keyCode);
        break;
    }
  }
  public void keyEvent(KeyEvent e) {
    if (!visible || !enabled || !textEditEnabled || !available) return;
    if (focusIsWith == this && endTLHI != null) {
      char keyChar = e.getKey();
      int keyCode = e.getKeyCode();
      int keyID = e.getAction();
      boolean shiftDown = e.isShiftDown();
      boolean ctrlDown = e.isControlDown();

      textChanged = false;
      keepCursorInView = true;

      int startPos = pos, startNbr = nbr;

      // Get selection details
      endChar = endTLHI.tli.startCharIndex + endTLHI.thi.getInsertionIndex();
      startChar =
          (startTLHI != null)
              ? startTLHI.tli.startCharIndex + startTLHI.thi.getInsertionIndex()
              : endChar;
      pos = endChar;
      nbr = 0;
      adjust = 0;
      if (endChar != startChar) { // Have we some text selected?
        if (startChar < endChar) { // Forward selection
          pos = startChar;
          nbr = endChar - pos;
        } else if (startChar > endChar) { // Backward selection
          pos = endChar;
          nbr = startChar - pos;
        }
      }
      if (startPos >= 0) {
        if (startPos != pos || startNbr != nbr) fireEvent(this, GEvent.SELECTION_CHANGED);
      }
      // Select either keyPressedProcess or keyTypeProcess. These two methods are overridden in
      // child classes
      if (keyID == KeyEvent.PRESS) {
        keyPressedProcess(keyCode, keyChar, shiftDown, ctrlDown);
        setScrollbarValues(ptx, pty);
      } else if (keyID
          == KeyEvent.TYPE) { // && e.getKey()  != KeyEvent.CHAR_UNDEFINED && !ctrlDown){
        keyTypedProcess(keyCode, keyChar, shiftDown, ctrlDown);
        setScrollbarValues(ptx, pty);
      }
      if (textChanged) {
        changeText();
        fireEvent(this, GEvent.CHANGED);
      }
    }
  }