processing.event.KeyEvent Java Examples

The following examples show how to use processing.event.KeyEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UITextInput.java    From haxademic with MIT License 6 votes vote down vote up
public void keyEvent(KeyEvent e) {
	if(active == false) return;
	if(ACTIVE_INPUT != this) return;
	if(e.getAction() == KeyEvent.PRESS) {
		char key = e.getKey();
		int keyCode = e.getKeyCode();
		// P.out(keyCode, PConstants.SHIFT);
		if(key == PConstants.BACKSPACE) {
			if(value.length() > 0) {
				value = value.substring( 0, value.length() - 1 );
			}
		} else if(key == PConstants.RETURN || key == PConstants.ENTER || keyCode == PConstants.SHIFT || key == PConstants.TAB) {
			// do nothing for special keys
		} else {
			value += key;
			if(filter != null) value = value.replaceAll(filter, "");
		}
	}
}
 
Example #2
Source File: DMXEditor.java    From haxademic with MIT License 6 votes vote down vote up
public void keyEvent(KeyEvent e) {
	if(e.getAction() == KeyEvent.PRESS) {
		if(e.getKey() == ']') {
			pointIndex++;
			if(pointIndex >= points.size()) pointIndex = 0;
			setActivePoint();
		}
		if(e.getKey() == '[') {
			pointIndex--;
			if(pointIndex < 0) pointIndex = points.size() - 1;
			setActivePoint();
		}
		if(e.getKey() == 's') saveLightsToFile();
		if(e.getKeyCode() == 147) deleteActiveLight();
		if(e.getKeyCode() == '`') showInfo = !showInfo;
	}
}
 
Example #3
Source File: SavedPointUI.java    From haxademic with MIT License 6 votes vote down vote up
public void keyEvent(KeyEvent e) {
	if(active == false) return;
	if(e.getAction() == KeyEvent.PRESS) {
		// shift
		if(e.getKeyCode() == P.SHIFT) shiftDown = true;
		// reset timeout
		if(e.getKeyCode() == P.UP || e.getKeyCode() == P.LEFT || e.getKeyCode() == P.RIGHT || e.getKeyCode() == P.DOWN) resetInteractionTimeout();
		// translate if arrow key
		Point translatePoint = new Point(0, 0);
		if(e.getKeyCode() == P.UP) translatePoint.setLocation(0, -1);
		if(e.getKeyCode() == P.LEFT) translatePoint.setLocation(-1, 0);
		if(e.getKeyCode() == P.RIGHT) translatePoint.setLocation(1, 0);
		if(e.getKeyCode() == P.DOWN) translatePoint.setLocation(0, 1);
		if(shiftDown) { translatePoint.x *= 10; translatePoint.y *= 10; }
		// apply transformation if needed
		if(translatePoint.x != 0 || translatePoint.y != 0) {
			position.add(translatePoint.x, translatePoint.y);
			save();
		}
	}
	if(e.getAction() == KeyEvent.RELEASE) {
		if(e.getKeyCode() == P.SHIFT) shiftDown = false;
	}
}
 
Example #4
Source File: SketchMapper.java    From sketch-mapper with MIT License 6 votes vote down vote up
/**
 * Invoked whenever a KeyEvent happens.
 *
 * @param event the KeyEvent.
 */
public void keyEvent(KeyEvent event) {
    if (surfaceMapper.getMode() == MODE_CALIBRATE) {
        for (SuperSurface surface : surfaceMapper.getSelectedSurfaces()) {
            mostRecentSurface = surface.getId();
        }

        if (java.awt.event.KeyEvent.VK_DELETE == event.getKeyCode()) {
            Iterator<SuperSurface> it = surfaceMapper.getSurfaces().iterator();
            while (it.hasNext()) {
                SuperSurface superSurface = it.next();
                if (superSurface.getId() == mostRecentSurface) {
                    it.remove();
                    surfaceMapper.getSelectedSurfaces().clear();
                    break;
                }
            }
        }
    }
    for (Sketch sketch : getSketchList()) {
        sketch.keyEvent(event);
    }
}
 
Example #5
Source File: PaperScreen.java    From PapARt with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Events coming from Processing to handle keys.
 *
 * @param e
 */
public void keyEvent(KeyEvent e) {

    String filename = "paper-" + Integer.toString(id) + ".xml";

    if (e.isAltDown() || !useAlt) {
        if (e.getAction() == KeyEvent.PRESS) {

            if (saveName == null) {
                System.err.println("This paperscreen does not have name ! \n Set it with setSaveName()");
            } else {
                filename = saveName;
            }

            if (saveKey != null
                    && (e.getKey() == saveKey.charAt(0))) {
                System.out.println("Saved to : " + filename);
                this.saveLocationTo(filename);
            }
            if (trackKey != null
                    && (e.getKey() == trackKey.charAt(0))) {
                this.useManualLocation(!this.useManualLocation, null);
                String status = useManualLocation ? "ON" : "OFF";
                System.out.println("PaperScreen: " + filename + " tracking: " + status);
            }
            if (loadKey != null
                    && (e.getKey() == loadKey.charAt(0))) {
                this.loadLocationFrom(filename);
                System.out.println("Loaded from: " + filename);
            }
        }
    }
}
 
Example #6
Source File: AudioIn.java    From haxademic with MIT License 5 votes vote down vote up
public void keyEvent(KeyEvent e) {
	if(e.getAction() == KeyEvent.PRESS) {
		if(e.getKey() == ',') {
			audioInput.audioData().setGain(audioInput.audioData().gain() - 0.05f);
			DebugView.setValue("audioData.gain()", audioInput.audioData().gain());
		} else if(e.getKey() == '.') {
			audioInput.audioData().setGain(audioInput.audioData().gain() + 0.05f);
			DebugView.setValue("audioData.gain()", audioInput.audioData().gain());
		}
	}
}
 
Example #7
Source File: UISlider.java    From haxademic with MIT License 5 votes vote down vote up
public void keyEvent(KeyEvent e) {
	if(isActive() == false) return;
	if(mouseHovered == false) return;
	if(e.getAction() == KeyEvent.PRESS) {
		if(e.getKeyCode() == P.LEFT) { value -= dragStep; value = P.max(value, valueMin); }
		if(e.getKeyCode() == P.RIGHT) { value += dragStep; value = P.min(value, valueMax); }
		if(saves) PrefToText.setValue(id, value);
	}
}
 
Example #8
Source File: KeyboardState.java    From haxademic with MIT License 5 votes vote down vote up
public void keyEvent(KeyEvent e) {
	if(e.getAction() == KeyEvent.PRESS) {
		setKeyOn(e.getKeyCode());
	}
	if(e.getAction() == KeyEvent.RELEASE) {
		setKeyOff(e.getKeyCode());
	}
}
 
Example #9
Source File: PGraphicsKeystone.java    From haxademic with MIT License 5 votes vote down vote up
public void keyEvent(KeyEvent e) {
	super.keyEvent(e);
	if(active == false) return;
	if(offsetsX == null || offsetsY == null) return;
	if(e.getAction() == KeyEvent.PRESS) {
		// fine controls
		if(e.getKey() == 'Z') {
			selectedColIndex--;
			if(selectedColIndex < -1) selectedColIndex = offsetsX.length - 1;
		}
		if(e.getKey() == 'X') {
			selectedColIndex++;
			if(selectedColIndex >= offsetsX.length) selectedColIndex = -1;
		}
		if(e.getKey() == 'C') {
			selectedRowIndex--;
			if(selectedRowIndex < -1) selectedRowIndex = offsetsY.length - 1;
		}
		if(e.getKey() == 'V')  {
			selectedRowIndex++;
			if(selectedRowIndex >= offsetsY.length) selectedRowIndex = -1;
		}
		if(e.getKey() == 'O')  fineControlAdjust(offsetsX, selectedColIndex, -1f);
		if(e.getKey() == 'P') fineControlAdjust(offsetsX, selectedColIndex, 1f);
		if(e.getKey() == '{') fineControlAdjust(offsetsY, selectedRowIndex, -1f);
		if(e.getKey() == '}') fineControlAdjust(offsetsY, selectedRowIndex, 1f);
		if(e.getKey() == 'E') saveConfig();
	}
}
 
Example #10
Source File: BaseSavedQuadUI.java    From haxademic with MIT License 5 votes vote down vote up
public void keyEvent(KeyEvent e) {
	if(active == false) return;
	if(e.getAction() == KeyEvent.PRESS) {
		// shift
		if(e.getKeyCode() == P.SHIFT) shiftDown = true;
		// reset timeout
		if(e.getKeyCode() == P.UP || e.getKeyCode() == P.LEFT || e.getKeyCode() == P.RIGHT || e.getKeyCode() == P.DOWN || e.getKeyCode() == P.TAB) resetInteractionTimeout();
		// translate if arrow key
		Point translatePoint = new Point(0, 0);
		if(e.getKeyCode() == P.UP) translatePoint.setLocation(0, -1);
		if(e.getKeyCode() == P.LEFT) translatePoint.setLocation(-1, 0);
		if(e.getKeyCode() == P.RIGHT) translatePoint.setLocation(1, 0);
		if(e.getKeyCode() == P.DOWN) translatePoint.setLocation(0, 1);
		if(shiftDown) { translatePoint.x *= 10; translatePoint.y *= 10; }
		// tab to next point
		if(e.getKeyCode() == P.TAB) {
			if(SELECTED_POINT == points[0]) SELECTED_POINT = points[1];
			else if(SELECTED_POINT == points[1]) SELECTED_POINT = points[2];
			else if(SELECTED_POINT == points[2]) SELECTED_POINT = points[3];
			else SELECTED_POINT = points[0];
			resetInteractionTimeout();
		}
		// apply transformation if needed
		if(translatePoint.x != 0 || translatePoint.y != 0) {
			if(SELECTED_POINT == points[0] || SELECTED_POINT == points[1] || SELECTED_POINT == points[2] || SELECTED_POINT == points[3]) {
				SELECTED_POINT.translate(translatePoint.x, translatePoint.y);
				save();
			} else if(DRAGGING_QUAD == this) {
				for( int i=0; i < points.length; i++ ) {
					points[i].translate(translatePoint.x, translatePoint.y);
				}
				save();
			}
		}
		updateCenter();
	}
	if(e.getAction() == KeyEvent.RELEASE) {
		if(e.getKeyCode() == P.SHIFT) shiftDown = false;
	}
}
 
Example #11
Source File: MapViewTileRenderer.java    From constellation with Apache License 2.0 5 votes vote down vote up
@Override
public void keyPressed(final KeyEvent event) {
    assert !SwingUtilities.isEventDispatchThread();

    if (key == PConstants.ESC) {
        // override exit behaviour
        key = 0;
    } else if (key == PConstants.CODED
            && (keyCode == PConstants.UP
            || keyCode == PConstants.DOWN
            || keyCode == PConstants.LEFT
            || keyCode == PConstants.RIGHT)) {
        // override move behaviour
        key = 0;
    } else {
        // switch map providers
        final int numberKey = (int) key - 48;
        if (numberKey <= parent.getProviders().size()
                && numberKey > 0 && numberKey < 10) {
            final MapProvider mapProvider = parent.getProviders().get(numberKey - 1);
            if (mapProvider != null) {
                switchProviders(mapProvider);
            }
        }
    }

    overlays.forEach(overlay -> overlay.keyPressed(event));
}
 
Example #12
Source File: Settings.java    From Project-16x16 with GNU General Public License v3.0 5 votes vote down vote up
@Override
void keyReleased(KeyEvent e) {
	switch (e.getKeyCode()) {
		case PConstants.ESC : // Pause
			game.returnScene();
			break;
		default :
			break;
	}
}
 
Example #13
Source File: MultiplayerMenu.java    From Project-16x16 with GNU General Public License v3.0 5 votes vote down vote up
@Override
void keyReleased(KeyEvent e) {
	switch (e.getKeyCode()) {
		case PConstants.ESC : // Pause
			game.returnScene();
			break;
		default :
			break;
	}
}
 
Example #14
Source File: PScene.java    From Project-16x16 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This method is <b>Public</b> only to enable binding to a parent PApplet.
 * <p>
 * You can <b>ignore this method</b> since the parent sketch will call it
 * automatically when it detects a key event (provided register() has been
 * called).
 */
public final void keyEvent(KeyEvent e) {
	switch (e.getAction()) {
		case KeyEvent.PRESS :
			keyPressed(e);
			break;
		case KeyEvent.RELEASE :
			keyReleased(e);
			break;
		default :
			break;
	}
}
 
Example #15
Source File: MainMenu.java    From Project-16x16 with GNU General Public License v3.0 5 votes vote down vote up
@Override
void keyReleased(KeyEvent e) {
	switch (e.getKeyCode()) {
		case 8 : // BACKSPACE
		case PConstants.ESC : // Pause
			game.returnScene();
			break;
		default :
			break;
	}
}
 
Example #16
Source File: MultiplayerHostMenu.java    From Project-16x16 with GNU General Public License v3.0 5 votes vote down vote up
@Override
void keyReleased(KeyEvent e) {
	switch (e.getKeyCode()) {
		case PConstants.ESC : // Pause
			game.returnScene();
			break;
		default :
			break;
	}
}
 
Example #17
Source File: AudioSettings.java    From Project-16x16 with GNU General Public License v3.0 5 votes vote down vote up
@Override
void keyReleased(KeyEvent e) {
	switch (e.getKeyCode()) {
		case PConstants.ESC : // Pause
			game.returnScene();
			break;
		default :
			break;
	}
}
 
Example #18
Source File: PauseMenu.java    From Project-16x16 with GNU General Public License v3.0 5 votes vote down vote up
@Override
void keyReleased(KeyEvent e) {
	switch (e.getKeyCode()) {
		case PConstants.ESC : // Pause
			game.returnScene();
			break;
		default :
			break;
	}
}
 
Example #19
Source File: MultiplayerClientMenu.java    From Project-16x16 with GNU General Public License v3.0 5 votes vote down vote up
@Override
void keyReleased(KeyEvent e) {
	switch (e.getKeyCode()) {
		case PConstants.ESC : // Pause
			game.returnScene();
			break;
		default :
			break;
	}
}
 
Example #20
Source File: ToolsOverlay.java    From constellation with Apache License 2.0 4 votes vote down vote up
@Override
public void keyPressed(final KeyEvent event) {
    // DO NOTHING
}
 
Example #21
Source File: RLangPApplet.java    From Processing.R with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void handleKeyEvent(KeyEvent event) {
  super.handleKeyEvent(event);
  wrapKeyVariables();
}
 
Example #22
Source File: Papart.java    From PapARt with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
     * KeyEvent to handle keys. No global keys analysed for now.
     *
     * @param e
     */
    public void keyEvent(KeyEvent e) {
//        if (e.getKey() == 'c') {
//            calibration();
//        }
    }
 
Example #23
Source File: OverviewOverlay.java    From constellation with Apache License 2.0 4 votes vote down vote up
@Override
public void keyPressed(final KeyEvent event) {
    // DO NOTHING
}
 
Example #24
Source File: TestSketchInvert.java    From sketch-mapper with MIT License 4 votes vote down vote up
@Override
public void keyEvent(KeyEvent event) {
	// TODO Auto-generated method stub

}
 
Example #25
Source File: InfoOverlay.java    From constellation with Apache License 2.0 4 votes vote down vote up
@Override
public void keyPressed(KeyEvent event) {
    // DO NOTHING
}
 
Example #26
Source File: BrightnessBumper.java    From haxademic with MIT License 4 votes vote down vote up
public void keyEvent(KeyEvent e) {
	if(e.getKey() == '-') bumpDown();
	if(e.getKey() == '=') bumpUp();
	if(e.getKey() == '0') brightness = 1f;
}
 
Example #27
Source File: MainSketch.java    From sketch-mapper with MIT License 2 votes vote down vote up
@Override
public void keyEvent(KeyEvent event) {

}
 
Example #28
Source File: PScene.java    From Project-16x16 with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Called automatically when the parent PApplet issues a <b>RELEASE</b>
 * {@link processing.event.KeyEvent KeyEvent}.
 * <p>
 * Therefore write any code here that should be executed when a key is
 * <b>released</b>.
 */
void keyReleased(KeyEvent e) {
}
 
Example #29
Source File: TestSketch.java    From sketch-mapper with MIT License 2 votes vote down vote up
@Override
public void keyEvent(KeyEvent event) {

}
 
Example #30
Source File: Sketch.java    From sketch-mapper with MIT License 2 votes vote down vote up
/**
 * This is the keyEvent callback method that will be propagated through
 * the {@link jto.processing.sketch.mapper.SketchMapper} object
 * and called on this sketch.
 *
 * @param event the key event.
 */
void keyEvent(KeyEvent event);