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

The following examples show how to use org.newdawn.slick.Input#KEY_LEFT . 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: TransformTest2.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @see org.newdawn.slick.BasicGame#keyPressed(int, char)
 */
public void keyPressed(int key, char c) {
   if (key == Input.KEY_ESCAPE) {
      System.exit(0);
   }
   if (key == Input.KEY_Q) {
      scaleUp = true;
   }
   if (key == Input.KEY_A) {
      scaleDown = true;
   }

   if( key == Input.KEY_LEFT) {
      moveLeft = true;
   }
   if( key == Input.KEY_UP ) {
      moveUp = true;
   }
   if( key == Input.KEY_RIGHT ) {
      moveRight = true;
   }
   if( key == Input.KEY_DOWN ) {
      moveDown = true;
   }
}
 
Example 2
Source File: TransformTest2.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @see org.newdawn.slick.BasicGame#keyReleased(int, char)
 */
public void keyReleased(int key, char c) {
   if (key == Input.KEY_Q) {
      scaleUp = false;
   }
   if (key == Input.KEY_A) {
      scaleDown = false;
   }
   
   if( key == Input.KEY_LEFT) {
      moveLeft = false;
   }
   if( key == Input.KEY_UP ) {
      moveUp = false;
   }
   if( key == Input.KEY_RIGHT ) {
      moveRight = false;
   }
   if( key == Input.KEY_DOWN ) {
      moveDown = false;
   }
}
 
Example 3
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();
			}
		}

	}
}