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

The following examples show how to use org.lwjgl.input.Keyboard#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: 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 2
Source File: Example2_2.java    From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void keyReleased(int key, char c) {
	switch(key) {
		case Keyboard.KEY_UP:
			dy = 0;
			break;
		case Keyboard.KEY_DOWN:
			dy = 0;
			break;
		case Keyboard.KEY_LEFT:
			dx = 0;
			break;
		case Keyboard.KEY_RIGHT:
			dx = 0;
			break;
	}
}
 
Example 3
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 4
Source File: Example2_2.java    From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void keyPressed(int key, char c) {
	switch(key) {
		case Keyboard.KEY_UP:
			dy = stepSize;
			break;
		case Keyboard.KEY_DOWN:
			dy = -stepSize;
			break;
		case Keyboard.KEY_LEFT:
			dx = -stepSize;
			break;
		case Keyboard.KEY_RIGHT:
			dx = stepSize;
			break;
	}
}
 
Example 5
Source File: GameCamera.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
private final boolean scrollSpeedLocked(int key) {
	return scroll_x != 0
		|| scroll_y != 0
		|| (LocalInput.isKeyDown(Keyboard.KEY_UP) && key != Keyboard.KEY_UP)
		|| (LocalInput.isKeyDown(Keyboard.KEY_DOWN) && key != Keyboard.KEY_DOWN)
		|| (LocalInput.isKeyDown(Keyboard.KEY_LEFT) && key != Keyboard.KEY_LEFT)
		|| (LocalInput.isKeyDown(Keyboard.KEY_RIGHT) && key != Keyboard.KEY_RIGHT);
}
 
Example 6
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 7
Source File: GuiInvItemSlot.java    From WirelessRedstone with MIT License 5 votes vote down vote up
@Override
public void keyTyped(char c, int keyindex)
{
    if(!focused)
        return;
    
    if(keyindex == Keyboard.KEY_LEFT)
        cyclePrevItem();
    if(keyindex == Keyboard.KEY_RIGHT)
        cycleNextItem();
    if(keyindex == Keyboard.KEY_RETURN && actionCommand != null)
        sendAction(actionCommand);
}
 
Example 8
Source File: GuiField.java    From WearableBackpacks with MIT License 5 votes vote down vote up
@Override
public void onKey(int keyCode, char keyChar) {
	if (!isEnabled() && (keyCode != Keyboard.KEY_LEFT) && (keyCode != Keyboard.KEY_RIGHT) &&
	                    (keyCode != Keyboard.KEY_HOME) && (keyCode != Keyboard.KEY_END)) return;
	
	String beforeText = getText();
	if (!Character.isISOControl(keyChar) && !isCharValid(keyChar)) return;
	_field.textboxKeyTyped(keyChar, keyCode);
	if (!getText().equals(beforeText)) onTextChanged();
}
 
Example 9
Source File: SliderButton.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public final void keyPressed(KeyboardEvent event) {
	switch (event.getKeyCode()) {
		case Keyboard.KEY_RIGHT:
			slider.setValue(slider.getValue() + 1);
			break;
		case Keyboard.KEY_LEFT:
			slider.setValue(slider.getValue() - 1);
			break;
	}
}
 
Example 10
Source File: LocationEditGui.java    From SkyblockAddons with MIT License 5 votes vote down vote up
/**
 * Allow moving the last hovered feature with arrow keys.
 */
@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
    super.keyTyped(typedChar, keyCode);
    Feature hoveredFeature = ButtonLocation.getLastHoveredFeature();
    if (hoveredFeature != null) {
        int xOffset = 0;
        int yOffset = 0;
        if (keyCode == Keyboard.KEY_LEFT) {
            xOffset--;
        } else if (keyCode == Keyboard.KEY_UP) {
            yOffset--;
        } else if (keyCode == Keyboard.KEY_RIGHT) {
            xOffset++;
        } else if (keyCode == Keyboard.KEY_DOWN) {
            yOffset++;
        }
        if (keyCode == Keyboard.KEY_A) {
            xOffset-= 10;
        } else if (keyCode == Keyboard.KEY_W) {
            yOffset-= 10;
        } else if (keyCode == Keyboard.KEY_D) {
            xOffset+= 10;
        } else if (keyCode == Keyboard.KEY_S) {
            yOffset+= 10;
        }
        main.getConfigValues().setCoords(hoveredFeature, main.getConfigValues().getRelativeCoords(hoveredFeature).getX()+xOffset,
                main.getConfigValues().getRelativeCoords(hoveredFeature).getY()+yOffset);
    }
}
 
Example 11
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 12
Source File: GuiSelectServer.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) {
        updateSelection(key == Keyboard.KEY_RIGHT ? 1 : -1);
    } else if (key == Keyboard.KEY_ESCAPE) {
        exit();
    }
}
 
Example 13
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 14
Source File: LwjglKeyboardHandleModule.java    From tprogers2048game with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Считывание последних данных из стека событий
 */
@Override
public void update() {
    resetValues();
    lastDirectionKeyPressed = Direction.AWAITING;

    while (Keyboard.next()) {
        if (Keyboard.getEventKeyState()) {
            switch(Keyboard.getEventKey()){
                case Keyboard.KEY_ESCAPE:
                    wasEscPressed = true;
                    break;
                case Keyboard.KEY_UP:
                    lastDirectionKeyPressed = Direction.UP;
                    break;
                case Keyboard.KEY_RIGHT:
                    lastDirectionKeyPressed = Direction.RIGHT;
                    break;
                case Keyboard.KEY_DOWN:
                    lastDirectionKeyPressed = Direction.DOWN;
                    break;
                case Keyboard.KEY_LEFT:
                    lastDirectionKeyPressed = Direction.LEFT;
                    break;
            }
        }
    }
}
 
Example 15
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 16
Source File: TabGui.java    From ClientBase with MIT License 5 votes vote down vote up
public void handleKey(int keycode) {
    if (keycode == Keyboard.KEY_DOWN) {
        if (selectedSubTab == -1) {
            selectedTab++;

            if (selectedTab >= tabs.size()) {
                selectedTab = 0;
            }
        } else {
            selectedSubTab++;

            if (selectedSubTab >= tabs.get(selectedTab).getSubTabs().size()) {
                selectedSubTab = 0;
            }
        }
    } else if (keycode == Keyboard.KEY_UP) {
        if (selectedSubTab == -1) {
            selectedTab--;

            if (selectedTab < 0) {
                selectedTab = tabs.size() - 1;
            }
        } else {
            selectedSubTab--;

            if (selectedSubTab < 0) {
                selectedSubTab = tabs.get(selectedTab).getSubTabs().size() - 1;
            }
        }
    } else if (keycode == Keyboard.KEY_LEFT) {
        selectedSubTab = -1;
    } else if (selectedSubTab == -1 && (keycode == Keyboard.KEY_RETURN || keycode == Keyboard.KEY_RIGHT)) {
        selectedSubTab = 0;
    } else if (keycode == Keyboard.KEY_RETURN || keycode == Keyboard.KEY_RIGHT) {
        tabs.get(selectedTab).getSubTabs().get(selectedSubTab).press();
    }
}
 
Example 17
Source File: GameCamera.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
public final void keyPressed(KeyboardEvent event) {
	switch (event.getKeyCode()) {
		case Keyboard.KEY_HOME:
		case Keyboard.KEY_NUMPAD8:
			break;
		case Keyboard.KEY_END:
		case Keyboard.KEY_NUMPAD2:
			break;
		case Keyboard.KEY_INSERT:
		case Keyboard.KEY_NUMPAD6:
			viewer.getPicker().pickRotate(this);
			break;
		case Keyboard.KEY_DELETE:
		case Keyboard.KEY_NUMPAD4:
			viewer.getPicker().pickRotate(this);
			break;
		case Keyboard.KEY_PRIOR:
		case Keyboard.KEY_NUMPAD9:
			mouseScrolled(-2);
			break;
		case Keyboard.KEY_NEXT:
		case Keyboard.KEY_NUMPAD3:
			mouseScrolled(2);
			break;
		case Keyboard.KEY_UP:
			if (!scrollSpeedLocked(Keyboard.KEY_UP)) {
				scroll_acceleration_seconds = 0;
				setScrollSpeed();
			}
			break;
		case Keyboard.KEY_DOWN:
			if (!scrollSpeedLocked(Keyboard.KEY_DOWN)) {
				scroll_acceleration_seconds = 0;
				setScrollSpeed();
			}
			break;
		case Keyboard.KEY_LEFT:
			if (!scrollSpeedLocked(Keyboard.KEY_LEFT)) {
				scroll_acceleration_seconds = 0;
				setScrollSpeed();
			}
			break;
		case Keyboard.KEY_RIGHT:
			if (!scrollSpeedLocked(Keyboard.KEY_RIGHT)) {
				scroll_acceleration_seconds = 0;
				setScrollSpeed();
			}
			break;
	}
}
 
Example 18
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();
}
 
Example 19
Source File: AbstractKey.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Get the name of the key being set for CustomKey
 *
 * @param keyCode opengl name of the key being pressed
 * @return the name of the key
 */
protected String getKeyOrMouseName(int keyCode) {
    if (keyCode < 0) {
        String openGLName = Mouse.getButtonName(keyCode + 100);
        if (openGLName != null) {
            if (openGLName.equalsIgnoreCase("button0")) return "LMB";
            if (openGLName.equalsIgnoreCase("button1")) return "RMB";
        }

        return openGLName;
    }

    if (mod.getSettings().isUsingLiteralKeys()) {
        switch (keyCode) {
            case Keyboard.KEY_GRAVE:
                return "~";
            case Keyboard.KEY_MINUS:
            case Keyboard.KEY_SUBTRACT:
                return "-";
            case Keyboard.KEY_APOSTROPHE:
                return "'";
            case Keyboard.KEY_LBRACKET:
                return "[";
            case Keyboard.KEY_RBRACKET:
                return "]";
            case Keyboard.KEY_BACKSLASH:
                return "\\";
            case Keyboard.KEY_DIVIDE:
            case Keyboard.KEY_SLASH:
                return "/";
            case Keyboard.KEY_COMMA:
                return ",";
            case Keyboard.KEY_PERIOD:
                return ".";
            case Keyboard.KEY_SEMICOLON:
                return ";";
            case Keyboard.KEY_EQUALS:
                return "=";
            case Keyboard.KEY_UP:
                return "▲";
            case Keyboard.KEY_DOWN:
                return "▼";
            case Keyboard.KEY_LEFT:
                return "◀";
            case Keyboard.KEY_RIGHT:
                return "▶";
            case Keyboard.KEY_MULTIPLY:
                return "*";
            case Keyboard.KEY_ADD:
                return "+";
        }
    }

    return Keyboard.getKeyName(keyCode);
}