Java Code Examples for org.lwjgl.input.Keyboard#KEY_BACK

The following examples show how to use org.lwjgl.input.Keyboard#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: TextField.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@Override
public boolean handleKeyPress(int keyID, char keyChar) {
    if (!focused())
        return false;

    if (keyID == Keyboard.KEY_BACK) {
        if (text.length() > 0) {
            setText(text.substring(0, text.length() - 1));
            backdowntime = System.currentTimeMillis();
        }
    } else if (keyID == Keyboard.KEY_RETURN || keyID == Keyboard.KEY_ESCAPE) {
        setFocus(false);
        onExit();
    } else if (keyChar == 22)//paste
    {
        String pastestring = GuiScreen.getClipboardString();
        if (pastestring == null)
            pastestring = "";

        if (isValid(text + pastestring))
            setText(text + pastestring);
    } else if (isValid(text + keyChar))
        setText(text + keyChar);

    return true;
}
 
Example 2
Source File: GuiLevelEmitterFluid.java    From ExtraCells1 with MIT License 6 votes vote down vote up
@Override
protected void keyTyped(char key, int keyID)
{
	super.keyTyped(key, keyID);
	if ("0123456789".contains(String.valueOf(key)) || keyID == Keyboard.KEY_BACK)
	{
		try
		{
			amountField.textboxKeyTyped(key, keyID);
			long currentFieldAmount = amountField.getText().isEmpty() ? 0 : Long.parseLong(amountField.getText());
			modifyAmount(currentFieldAmount - tileentity.getAmount());
		} catch (Throwable e)
		{
		}
	}
}
 
Example 3
Source File: GuiReactorRedstonePort.java    From BigReactors with MIT License 6 votes vote down vote up
private boolean isKeyValidForValueInput(int keyCode) {
	if(keyCode >= Keyboard.KEY_1 && keyCode <= Keyboard.KEY_0) { return true; }
	switch(keyCode) {
		case Keyboard.KEY_NUMPAD0:
		case Keyboard.KEY_NUMPAD1:
		case Keyboard.KEY_NUMPAD2:
		case Keyboard.KEY_NUMPAD3:
		case Keyboard.KEY_NUMPAD4:
		case Keyboard.KEY_NUMPAD5:
		case Keyboard.KEY_NUMPAD6:
		case Keyboard.KEY_NUMPAD7:
		case Keyboard.KEY_NUMPAD8:
		case Keyboard.KEY_NUMPAD9:
		case Keyboard.KEY_DELETE:
		case Keyboard.KEY_BACK:
		case Keyboard.KEY_LEFT:
		case Keyboard.KEY_RIGHT:
			return true;
		default:
			return false;
	}
}
 
Example 4
Source File: TextBoxElement.java    From Slyther with MIT License 6 votes vote down vote up
@Override
public void keyPressed(int key, char character) {
    if (selected) {
        boolean modified = false;
        if (key == Keyboard.KEY_BACK) {
            if (text.length() > 0 && selectionIndex > 0) {
                text = text.substring(0, Math.max(0, selectionIndex - 1)) + text.substring(selectionIndex);
                selectionIndex--;
                modified = true;
            }
        } else if (character != 167 && character >= 32 && character != 127) {
            text = text.substring(0, selectionIndex) + character + text.substring(selectionIndex);
            selectionIndex++;
            modified = true;
        } else if (key == Keyboard.KEY_LEFT && selectionIndex > 0) {
            selectionIndex--;
        } else if (key == Keyboard.KEY_RIGHT && selectionIndex < text.length()) {
            selectionIndex++;
        }
        if (modified) {
            function.apply(this);
        }
    }
}
 
Example 5
Source File: TextField.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@Override
public boolean handleKeyPress(int keyID, char keyChar) {
    if (!focused()) {
        return false;
    }

    if (keyID == Keyboard.KEY_BACK) {
        if (text.length() > 0) {
            setText(text.substring(0, text.length() - 1));
            backdowntime = System.currentTimeMillis();
        }
    } else if (keyID == Keyboard.KEY_RETURN || keyID == Keyboard.KEY_ESCAPE) {
        setFocus(false);
        onExit();
    } else if (keyChar == 22) {//paste
        String pastestring = GuiScreen.getClipboardString();
        if (pastestring == null) {
            pastestring = "";
        }

        if (isValid(text + pastestring)) {
            setText(text + pastestring);
        }
    } else if (isValid(text + keyChar)) {
        setText(text + keyChar);
    }

    return true;
}
 
Example 6
Source File: SaveLoadButton.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@Override
public boolean handleKeyPress(int keyID, char keyChar) {
    if (!focused) {
        return false;
    }

    if (keyID == Keyboard.KEY_BACK) {
        if (label.length() > 0) {
            label = label.substring(0, label.length() - 1);
            onTextChange();
            backdowntime = System.currentTimeMillis();
        }
    } else if (keyID == Keyboard.KEY_RETURN) {
        focused = false;
    } else if (keyChar == 22)//paste
    {
        String pastestring = GuiScreen.getClipboardString();
        if (pastestring == null) {
            pastestring = "";
        }

        label = label + pastestring;
        onTextChange();
    } else if (ChatAllowedCharacters.isAllowedCharacter(keyChar)) {
        label = label + keyChar;
        onTextChange();
    }
    return true;
}
 
Example 7
Source File: GuiSelectSkin.java    From Slyther with MIT License 5 votes vote down vote up
@Override
public void keyPressed(int key, char character) {
    if (key == Keyboard.KEY_RIGHT || key == Keyboard.KEY_LEFT) {
        updateSkin(key == Keyboard.KEY_RIGHT);
    } else if (key == Keyboard.KEY_ESCAPE || key == Keyboard.KEY_BACK) {
        exit();
    }
}
 
Example 8
Source File: GuiGame.java    From Slyther with MIT License 5 votes vote down vote up
@Override
public void keyPressed(int key, char character) {
    if (key == Keyboard.KEY_BACK || key == Keyboard.KEY_ESCAPE) {
        client.close();
        closeGui();
    }
}
 
Example 9
Source File: GuiSpaceLaser.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
protected void keyTyped(char par1, int par2) throws IOException
{
	//Don't let players change the coords while the machine is running
	if(!laserTile.isRunning()) {
		if(Character.isDigit(par1) || par1 == '-' || par2 == Keyboard.KEY_BACK || par2 == Keyboard.KEY_DELETE || par2 == Keyboard.KEY_LEFT || par2 == Keyboard.KEY_RIGHT) {
			if(xbox.isFocused() && (par1 != '-' || (xbox.getCursorPosition() == 0 && !xbox.getText().startsWith("-")))) {
				xbox.textboxKeyTyped(par1, par2);

				if(!xbox.getText().isEmpty() && !xbox.getText().contentEquals("-"))
					laserTile.laserX = Integer.parseInt(xbox.getText());

				PacketHandler.sendToServer(new PacketMachine(laserTile,(byte) 0));
			}
			else if(ybox.isFocused() && (par1 != '-' || (ybox.getCursorPosition() == 0 && !ybox.getText().startsWith("-")))){
				ybox.textboxKeyTyped(par1, par2);
				if(!ybox.getText().isEmpty() && !ybox.getText().contentEquals("-"))
					laserTile.laserZ = Integer.parseInt(ybox.getText());

				PacketHandler.sendToServer(new PacketMachine(laserTile,(byte) 1));
			}
		}
	}

	if(par2 == Keyboard.KEY_TAB) {
		if(xbox.isFocused()) {
			xbox.setFocused(false);
			ybox.setFocused(true);
		}
		else if(ybox.isFocused()) {
			xbox.setFocused(true);
			ybox.setFocused(false);
		}
	}
	
	super.keyTyped(par1, par2);
}
 
Example 10
Source File: GuiTextInput.java    From ForgeHax with MIT License 5 votes vote down vote up
public void keyTyped(char typedChar, int keyCode) throws IOException {
  if (isActive) {
    switch (keyCode) {
      case Keyboard.KEY_ESCAPE:
        isActive = false;
        break;
      
      case Keyboard.KEY_RETURN:
        isActive = false;
        // setValue(input);
        MC.player.sendMessage(new TextComponentString(input.toString()));
        break;
      
      case Keyboard.KEY_BACK:
        if (selectedIndex > -1) {
          input.deleteCharAt(selectedIndex);
          selectedIndex--;
        }
        break;
      
      case Keyboard.KEY_LEFT:
        selectedIndex--;
        break;
      
      case Keyboard.KEY_RIGHT:
        selectedIndex++;
        break;
      
      default:
        if (isValidChar(typedChar)) {
          selectedIndex++;
          input.insert(selectedIndex, typedChar);
        }
    }
    selectedIndex = MathHelper.clamp(selectedIndex, -1, input.length() - 1);
  }
}
 
Example 11
Source File: GuiOptionPane.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@Override
public void keyTyped(char c, int keycode) throws IOException {
    if (keycode == Keyboard.KEY_ESCAPE || keycode == Keyboard.KEY_BACK) {
        Minecraft.getMinecraft().displayGuiScreen(getParentScreen());
        return;
    }
    super.keyTyped(c, keycode);
}
 
Example 12
Source File: GuiItemIconDumper.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@Override
protected void keyTyped(char c, int keycode) throws IOException {
    if (keycode == Keyboard.KEY_ESCAPE || keycode == Keyboard.KEY_BACK) {
        returnScreen(new ChatComponentTranslation(opt.fullName()+".icon.cancelled"));
        return;
    }
    super.keyTyped(c, keycode);
}
 
Example 13
Source File: GuiHighlightTips.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@Override
public void keyTyped(char c, int keycode) throws IOException {
    if (keycode == Keyboard.KEY_ESCAPE || keycode == Keyboard.KEY_BACK) {
        Minecraft.getMinecraft().displayGuiScreen(opt.slot.getGui());
        return;
    }
    super.keyTyped(c, keycode);
}
 
Example 14
Source File: SaveLoadButton.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@Override
public boolean handleKeyPress(int keyID, char keyChar)
{
    if(!focused)
        return false;
    
    if(keyID == Keyboard.KEY_BACK)
    {
        if(label.length() > 0)
        {
            label = label.substring(0, label.length() - 1);
            onTextChange();
            backdowntime = System.currentTimeMillis();
        }
    }
    else if(keyID == Keyboard.KEY_RETURN)
    {
        focused = false;
    }        
    else if(keyChar == 22)//paste
    {
        String pastestring = GuiScreen.getClipboardString();
        if(pastestring == null) 
            pastestring = "";

        label = label + pastestring;
        onTextChange();
    }
    else if(ChatAllowedCharacters.isAllowedCharacter(keyChar))
    {
        label = label + keyChar;
        onTextChange();
    }
    return true;
}
 
Example 15
Source File: GuiCCTextField.java    From CodeChickenCore with MIT License 5 votes vote down vote up
@Override
public void keyTyped(char c, int keycode)
{
    if(!isEnabled || !isFocused)
        return;

    /*if(c == '\t')//tab
    {
        parentGuiScreen.selectNextField();
    }*/
    if(c == '\026')//paste
    {
        String s = GuiScreen.getClipboardString();
        if(s == null || s.equals(""))
            return;

        for(int i = 0; i < s.length(); i++)
        {
            if(text.length() == maxStringLength)
                return;

            char tc = s.charAt(i);
            if(canAddChar(tc))
                setText(text + tc);
        }
    }
    if(keycode == Keyboard.KEY_RETURN)
    {
        setFocused(false);
        sendAction(actionCommand, getText());
    }

    if(keycode == Keyboard.KEY_BACK && text.length() > 0)
        setText(text.substring(0, text.length() - 1));

    if((text.length() < maxStringLength || maxStringLength == 0) && canAddChar(c))
        setText(text + c);
}
 
Example 16
Source File: GuiSaveSlotButton.java    From NBTEdit with GNU General Public License v3.0 5 votes vote down vote up
public void keyTyped(char c, int key) {
	if (key == Keyboard.KEY_BACK){
		backSpace();
	}
	if (Character.isDigit(c) || Character.isLetter(c)){
		save.name += c;
		text = (save.tag.hasNoTags() ? "Save " : "Load ") + save.name;
		updatePosition();
	}
}
 
Example 17
Source File: TextInputBox.java    From FEMultiplayer with GNU General Public License v3.0 5 votes vote down vote up
public void beginStep() {
	if(hasFocus) {
		List<KeyboardEvent> keys = Game.getKeys();
		for(KeyboardEvent ke : keys) {
			if(ke.state) {
				char c = ke.eventChar;
				if(isValidCharacter(c) && FEResources.getBitmapFont("default_med")
						.getStringWidth(input.toString()+c) < 246) {
					input.insert(cursorPos, c);
					cursorPos++;
				} else {
					if(ke.key == Keyboard.KEY_LEFT && cursorPos > 0) { 
						cursorPos--;
					}
					else if(ke.key == Keyboard.KEY_RIGHT && cursorPos < input.length()) { 
						cursorPos++;
					}
					else if(ke.key == Keyboard.KEY_BACK && cursorPos > 0) { 
						input.deleteCharAt(cursorPos-1);
						cursorPos--;
					}
					else if(ke.key == Keyboard.KEY_DELETE && cursorPos < input.length()) { 
						input.deleteCharAt(cursorPos);
					}
				}
			}
		}
	}
}
 
Example 18
Source File: GuiItemIconDumper.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@Override
protected void keyTyped(char c, int keycode) throws IOException {
    if (keycode == Keyboard.KEY_ESCAPE || keycode == Keyboard.KEY_BACK) {
        returnScreen(new TextComponentTranslation(opt.fullName() + ".icon.cancelled"));
        return;
    }
    super.keyTyped(c, keycode);
}
 
Example 19
Source File: GuiOptionPane.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@Override
public void keyTyped(char c, int keycode) throws IOException {
    if (keycode == Keyboard.KEY_ESCAPE || keycode == Keyboard.KEY_BACK) {
        Minecraft.getMinecraft().displayGuiScreen(getParentScreen());
        return;
    }
    super.keyTyped(c, keycode);
}
 
Example 20
Source File: EditBox.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
protected final void keyRepeat(KeyboardEvent event) {
	//char ch = event.getKeyChar();
	Box edit_box = Skin.getSkin().getEditBox();
	switch (event.getKeyCode()) {
		case Keyboard.KEY_RETURN:
			if (insert(index, '\n')) {
				index++;
			}
			break;
		case Keyboard.KEY_BACK:
			if (index > 0)
				delete(--index);
			break;
		case Keyboard.KEY_DELETE:
			if (index < getText().length())
				delete(index);
			break;
		case Keyboard.KEY_LEFT:
			if (index > 0)
				index--;
			break;
		case Keyboard.KEY_RIGHT:
			if (index < getText().length())
				index++;
			break;
		case Keyboard.KEY_UP:
			index = getTextRenderer().jump(edit_box.getLeftOffset(),
										   edit_box.getBottomOffset(),
										   0,
										   getFont().getHeight(),
										   getText(),
										   index);
			break;
		case Keyboard.KEY_DOWN:
			index = getTextRenderer().jump(edit_box.getLeftOffset(),
										   edit_box.getBottomOffset(),
										   0,
										   -getFont().getHeight(),
										   getText(),
										   index);
			break;
		case Keyboard.KEY_HOME:
			index = getTextRenderer().jump(edit_box.getLeftOffset(),
										   edit_box.getBottomOffset(),
										   -getWidth(),
										   0,
										   getText(),
										   index);
			break;
		case Keyboard.KEY_END:
			index = getTextRenderer().jump(edit_box.getLeftOffset(),
										   edit_box.getBottomOffset(),
										   getWidth(),
										   0,
										   getText(),
										   index);
			break;
		case Keyboard.KEY_TAB:
		case Keyboard.KEY_ESCAPE:
			super.keyRepeat(event);
			break;
		default:
			char key = event.getKeyChar();
			if (getFont().getQuad(key) != null) {
				if (insert(index, key))
					index++;
			} else {
				super.keyRepeat(event);
			}
			
			break;
	}
	correctOffsetY();
}