Java Code Examples for processing.event.KeyEvent#getKeyCode()

The following examples show how to use processing.event.KeyEvent#getKeyCode() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
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);
	}
}