Java Code Examples for org.newdawn.slick.Input#KEY_BACK

The following examples show how to use org.newdawn.slick.Input#KEY_BACK . 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: StateConfigJoystickButton.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * When a key is pressed
 * @param key Keycode
 */
protected void onKey(int key) {
	if(frame >= KEYACCEPTFRAME) {
		// Up
		if(key == Input.KEY_UP) {
			ResourceHolderSlick.soundManager.play("cursor");
			keynum--;
			if(keynum < 4) keynum = 15;
		}
		// Down
		else if(key == Input.KEY_DOWN) {
			ResourceHolderSlick.soundManager.play("cursor");
			keynum++;
			if(keynum > 15) keynum = 4;
		}
		// Delete
		else if(key == Input.KEY_DELETE) {
			ResourceHolderSlick.soundManager.play("change");
			buttonmap[keynum] = -1;
		}
		// Backspace
		else if(key == Input.KEY_BACK) {
			gameObj.enterState(StateConfigJoystickMain.ID);
			return;
		}
		// Enter/Return
		else if(key == Input.KEY_ENTER) {
			ResourceHolderSlick.soundManager.play("decide");

			for(int i = 0; i < GameKeySlick.MAX_BUTTON; i++) {
				GameKeySlick.gamekey[player].buttonmap[i] = buttonmap[i];
			}
			GameKeySlick.gamekey[player].saveConfig(NullpoMinoSlick.propConfig);
			NullpoMinoSlick.saveConfig();

			gameObj.enterState(StateConfigJoystickMain.ID);
			return;
		}
	}
}
 
Example 2
Source File: StateConfigJoystickTest.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * When a key is pressed
 * @param key Keycode
 */
protected void onKey(int key) {
	if(frame >= KEYACCEPTFRAME) {
		// Backspace & Enter/Return
		if((key == Input.KEY_BACK) || (key == Input.KEY_RETURN)) {
			gameObj.enterState(StateConfigJoystickMain.ID);
		}
	}
}
 
Example 3
Source File: StateConfigKeyboard.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * When a key is released
 * @param key Keycode
 */
protected void onKey(int key) {
	if(frame >= KEYACCEPTFRAME) {
		if(keyConfigRestFrame > 0) {
			// Key-set mode
			ResourceHolderSlick.soundManager.play("move");
			keymap[keynum] = key;
			keyConfigRestFrame = 0;
		} else {
			// Menu mode
			if(key == Input.KEY_UP) {
				ResourceHolderSlick.soundManager.play("cursor");
				keynum--;
				if(keynum < 0) keynum = NUM_KEYS;
			}
			if(key == Input.KEY_DOWN) {
				ResourceHolderSlick.soundManager.play("cursor");
				keynum++;
				if(keynum > NUM_KEYS) keynum = 0;
			}

			// Enter
			if(key == Input.KEY_ENTER) {
				ResourceHolderSlick.soundManager.play("decide");

				if(keynum >= NUM_KEYS) {
					// Save & Exit
					for(int i = 0; i < NUM_KEYS; i++) {
						if(!isNavSetting)
							GameKeySlick.gamekey[player].keymap[i] = keymap[i];
						else
							GameKeySlick.gamekey[player].keymapNav[i] = keymap[i];
					}
					GameKeySlick.gamekey[player].saveConfig(NullpoMinoSlick.propConfig);
					NullpoMinoSlick.saveConfig();
					gameObj.enterState(StateConfigMainMenu.ID);
				} else {
					// Set key
					keyConfigRestFrame = 60 * 5;
				}
				return;
			}

			// Delete
			if(key == Input.KEY_DELETE) {
				if((keynum < NUM_KEYS) && (keymap[keynum] != 0)) {
					ResourceHolderSlick.soundManager.play("change");
					keymap[keynum] = 0;
				}
			}

			// Backspace
			if(key == Input.KEY_BACK) {
				if(isNavSetting)
					gameObj.enterState(StateConfigKeyboardNavi.ID);
				else
					gameObj.enterState(StateConfigMainMenu.ID);
			}
		}
	}
}
 
Example 4
Source File: DownloadsMenu.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void keyPressed(int key, char c) {
	// block input during beatmap importing
	if (importThread != null && !(key == Input.KEY_ESCAPE || key == Input.KEY_F12))
		return;

	if (UI.globalKeyPressed(key))
		return;

	switch (key) {
	case Input.KEY_ESCAPE:
		if (importThread != null) {
			// beatmap importing: stop parsing beatmaps by sending interrupt to BeatmapParser
			importThread.interrupt();
		} else if (!search.getText().isEmpty()) {
			// clear search text
			search.setText("");
			pageDir = Page.RESET;
			resetSearchTimer();
		} else {
			// return to main menu
			SoundController.playSound(SoundEffect.MENUBACK);
			((MainMenu) game.getState(Opsu.STATE_MAINMENU)).reset();
			game.enterState(Opsu.STATE_MAINMENU, new EasedFadeOutTransition(), new FadeInTransition());
		}
		break;
	case Input.KEY_ENTER:
		if (!search.getText().isEmpty()) {
			pageDir = Page.RESET;
			resetSearchTimer();
		}
		break;
	case Input.KEY_F5:
		SoundController.playSound(SoundEffect.MENUCLICK);
		lastQuery = null;
		pageDir = Page.CURRENT;
		if (searchQuery != null)
			searchQuery.interrupt();
		resetSearchTimer();
		break;
	default:
		// wait for user to finish typing
		if (Character.isLetterOrDigit(c) || key == Input.KEY_BACK || key == Input.KEY_SPACE) {
			// load glyphs
			if (c > 255)
				Fonts.loadGlyphs(searchFont, c);

			// reset search timer
			searchTimer = 0;
			pageDir = Page.RESET;
		}
		break;
	}
}
 
Example 5
Source File: TextField.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @see org.newdawn.slick.gui.AbstractComponent#keyPressed(int, char)
 */
public void keyPressed(int key, char c) {
	if (hasFocus()) {
		if (key != -1)
		{
			if ((key == Input.KEY_V) && 
			   ((input.isKeyDown(Input.KEY_LCONTROL)) || (input.isKeyDown(Input.KEY_RCONTROL)))) {
				String text = Sys.getClipboard();
				if (text != null) {
					doPaste(text);
				}
				return;
			}
			if ((key == Input.KEY_Z) && 
			   ((input.isKeyDown(Input.KEY_LCONTROL)) || (input.isKeyDown(Input.KEY_RCONTROL)))) {
				if (oldText != null) {
					doUndo(oldCursorPos, oldText);
				}
				return;
			}
			
			// alt and control keys don't come through here
			if (input.isKeyDown(Input.KEY_LCONTROL) || input.isKeyDown(Input.KEY_RCONTROL)) {
				return;
			}
			if (input.isKeyDown(Input.KEY_LALT) || input.isKeyDown(Input.KEY_RALT)) {
				return;
			}
		}
		
		if (lastKey != key) {
			lastKey = key;
			repeatTimer = System.currentTimeMillis() + INITIAL_KEY_REPEAT_INTERVAL;
		} else {
			repeatTimer = System.currentTimeMillis() + KEY_REPEAT_INTERVAL;
		}
		lastChar = c;
		
		if (key == Input.KEY_LEFT) {
			if (cursorPos > 0) {
				cursorPos--;
			}
			// Nobody more will be notified
			if (consume) {
				container.getInput().consumeEvent();
			}
		} else if (key == Input.KEY_RIGHT) {
			if (cursorPos < value.length()) {
				cursorPos++;
			}
			// Nobody more will be notified
			if (consume) {
				container.getInput().consumeEvent();
			}
		} else if (key == Input.KEY_BACK) {
			if ((cursorPos > 0) && (value.length() > 0)) {
				if (cursorPos < value.length()) {
					value = value.substring(0, cursorPos - 1)
							+ value.substring(cursorPos);
				} else {
					value = value.substring(0, cursorPos - 1);
				}
				cursorPos--;
			}
			// Nobody more will be notified
			if (consume) {
				container.getInput().consumeEvent();
			}
		} else if (key == Input.KEY_DELETE) {
			if (value.length() > cursorPos) {
				value = value.substring(0,cursorPos) + value.substring(cursorPos+1);
			}
			// Nobody more will be notified
			if (consume) {
				container.getInput().consumeEvent();
			}
		} else if ((c < 127) && (c > 31) && (value.length() < maxCharacter)) {
			if (cursorPos < value.length()) {
				value = value.substring(0, cursorPos) + c
						+ value.substring(cursorPos);
			} else {
				value = value.substring(0, cursorPos) + c;
			}
			cursorPos++;
			// Nobody more will be notified
			if (consume) {
				container.getInput().consumeEvent();
			}
		} else if (key == Input.KEY_RETURN) {
			notifyListeners();
			// Nobody more will be notified
			if (consume) {
				container.getInput().consumeEvent();
			}
		}

	}
}