Java Code Examples for org.lwjgl.input.Keyboard#isKeyDown()

The following examples show how to use org.lwjgl.input.Keyboard#isKeyDown() . 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: HotGive.java    From ehacks-pro with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onTicks() {
    try {
        boolean newState = Keyboard.isKeyDown(GiveKeybind.getKey());
        if (newState && !prevState) {
            prevState = newState;
            MovingObjectPosition mop = Wrapper.INSTANCE.mc().objectMouseOver;
            TileEntity entity = Wrapper.INSTANCE.world().getTileEntity(mop.blockX, mop.blockY, mop.blockZ);
            if (entity != null && Class.forName("cofh.thermalexpansion.block.cache.TileCache").isInstance(entity)) {
                setSlot(entity, Statics.STATIC_ITEMSTACK);
                InteropUtils.log("Set", this);
            }
        }
        prevState = newState;
    } catch (Exception e) {
    }
}
 
Example 2
Source File: Example11_3.java    From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void update(long deltaTime) {
	Utils.updateMousePoles(viewPole, objectPole);
	
	lightTimer.update(deltaTime);
	
	float speed = (deltaTime / (float)1e9) * (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) ? 0.5f : 2f);
	
	if(Keyboard.isKeyDown(Keyboard.KEY_I))
		lightHeight += speed;
	if(Keyboard.isKeyDown(Keyboard.KEY_K))
		lightHeight -= speed;
	if(Keyboard.isKeyDown(Keyboard.KEY_L))
		lightRadius += speed;
	if(Keyboard.isKeyDown(Keyboard.KEY_J))
		lightRadius -= speed;
	
	if(lightRadius < 0.2f)
		lightRadius = 0.2f;
}
 
Example 3
Source File: Example8_2.java    From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void update(long deltaTime) {
	float speed = 90 * deltaTime / (float)1e9;
	
	if(Keyboard.isKeyDown(Keyboard.KEY_W))
		offsetOrientation(new Vector3(1, 0, 0), speed);
	if(Keyboard.isKeyDown(Keyboard.KEY_S))
		offsetOrientation(new Vector3(1, 0, 0), -speed);
	
	if(Keyboard.isKeyDown(Keyboard.KEY_A))
		offsetOrientation(new Vector3(0, 0, 1), speed);
	if(Keyboard.isKeyDown(Keyboard.KEY_D))
		offsetOrientation(new Vector3(0, 0, 1), -speed);
	
	if(Keyboard.isKeyDown(Keyboard.KEY_Q))
		offsetOrientation(new Vector3(0, 1, 0), speed);
	if(Keyboard.isKeyDown(Keyboard.KEY_E))
		offsetOrientation(new Vector3(0, 1, 0), -speed);
}
 
Example 4
Source File: Camera.java    From OpenRS with GNU General Public License v3.0 5 votes vote down vote up
public static void acceptInputGrab() {
    if(Mouse.isInsideWindow() && Mouse.isButtonDown(0)) {
        Mouse.setGrabbed(true);
    }
    if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
        Mouse.setGrabbed(false);
    }
}
 
Example 5
Source File: NEIClientUtils.java    From NotEnoughItems with MIT License 5 votes vote down vote up
public static boolean safeKeyDown(int keyCode) {
    try {
        return Keyboard.isKeyDown(keyCode);
    } catch (IndexOutOfBoundsException e) {
        return false;
    }
}
 
Example 6
Source File: RedHack.java    From ehacks-pro with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onTicks() {
    boolean newState = Keyboard.isKeyDown(GiveKeybind.getKey());
    if (newState && !prevState) {
        prevState = newState;
        int slotId = Wrapper.INSTANCE.player().inventory.currentItem;
        if (Statics.STATIC_ITEMSTACK == null) {
            return;
        }
        setRed(Statics.STATIC_ITEMSTACK, slotId);
        InteropUtils.log("Set", this);
    }
    prevState = newState;
}
 
Example 7
Source File: DraggableHudComponent.java    From seppuku with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void mouseRelease(int mouseX, int mouseY, int button) {
    super.mouseRelease(mouseX, mouseY, button);

    if (button == 0) {
        if (this.isDragging()) {
            if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) || !this.isSnappable()) {
                this.setDragging(false);
                return;
            }

            this.anchorPoint = this.findClosest(mouseX, mouseY);

            for (HudComponent component : Seppuku.INSTANCE.getHudManager().getComponentList()) {
                if (component instanceof DraggableHudComponent) {
                    DraggableHudComponent draggable = (DraggableHudComponent) component;
                    if (draggable != this && this.collidesWith(draggable) && draggable.isVisible() && draggable.isSnappable()) {
                        if ((this.getY() + (this.getH() / 2)) < (draggable.getY() + (draggable.getH() / 2))) { // top
                            this.setY(draggable.getY() - this.getH());
                            this.glueSide = GlueSide.TOP;
                            this.glued = draggable;
                            if (draggable.getAnchorPoint() != null) {
                                this.anchorPoint = draggable.getAnchorPoint();
                            }
                        } else if ((this.getY() + (this.getH() / 2)) > (draggable.getY() + (draggable.getH() / 2))) { // bottom
                            this.setY(draggable.getY() + draggable.getH());
                            this.glueSide = GlueSide.BOTTOM;
                            this.glued = draggable;
                            if (draggable.getAnchorPoint() != null) {
                                this.anchorPoint = draggable.getAnchorPoint();
                            }
                        }
                    }
                }
            }
        }

        this.setDragging(false);
    }
}
 
Example 8
Source File: GuiTextArea.java    From pycode-minecraft with MIT License 5 votes vote down vote up
public void scrollBy(int amount) {
    if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
        // TODO this reversal should probably be simplified??
        this.textXOffset -= amount;
    } else {
        this.textYOffset += amount;
    }
    FMLLog.info("text offset = %d, %d", textXOffset, textYOffset);
}
 
Example 9
Source File: Widget.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SideOnly(Side.CLIENT)
protected boolean isShiftDown() {
    return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
}
 
Example 10
Source File: Input.java    From opsu-dance with GNU General Public License v3.0 4 votes vote down vote up
public boolean isShiftDown()
{
	return Keyboard.isKeyDown(KEY_RSHIFT) || Keyboard.isKeyDown(KEY_LSHIFT);
}
 
Example 11
Source File: ContainerManager.java    From CraftingKeys with MIT License 4 votes vote down vote up
/**
 * Handles what to do with NumKey-Inputs while holding a item.
 *
 * @param currentHoveredSlot slot where the mouse is right now
 */
void handleNumKey(Slot currentHoveredSlot) {

    // hotbar-slots are always the last 9 slots of the currently opened inventory
    int hotbarStartIndex = Util.client.player.openContainer.getInventory().size() - 9 - 1;

    if (Util.client.currentScreen instanceof GuiInventory) {
        hotbarStartIndex -= 1;
    }

    int inputdelta;
    KeyBinding[] hotbar = Util.client.gameSettings.keyBindsHotbar;

    if (Keyboard.isKeyDown(hotbar[0].getKeyCode())) {
        inputdelta = 1;
    } else if (Keyboard.isKeyDown(hotbar[1].getKeyCode())) {
        inputdelta = 2;
    } else if (Keyboard.isKeyDown(hotbar[2].getKeyCode())) {
        inputdelta = 3;
    } else if (Keyboard.isKeyDown(hotbar[3].getKeyCode())) {
        inputdelta = 4;
    } else if (Keyboard.isKeyDown(hotbar[4].getKeyCode())) {
        inputdelta = 5;
    } else if (Keyboard.isKeyDown(hotbar[5].getKeyCode())) {
        inputdelta = 6;
    } else if (Keyboard.isKeyDown(hotbar[6].getKeyCode())) {
        inputdelta = 7;
    } else if (Keyboard.isKeyDown(hotbar[7].getKeyCode())) {
        inputdelta = 8;
    } else if (Keyboard.isKeyDown(hotbar[8].getKeyCode())) {
        inputdelta = 9;
    } else {
        return;
    }

    // If no stack is held and a num-key is pressed, get the output by interaction, but only
    // if there could not be meant another stack at mouse position. cool logic!
    if (!Util.isHoldingStack()) {

        if (currentHoveredSlot == null || !currentHoveredSlot.getHasStack()) {
            Logger.info("handleNumKey()", "Trying output to hotbar speedup.");
            onInteractionKeyPressed();
        }
    }

    // If held, move!
    if (Util.isHoldingStack()) {

        leftClick(hotbarStartIndex + inputdelta);
        Logger.info("handleNumKey()", "Moved to hotbar slot " + inputdelta + ".");

        moveStackToInventory(-1);

        // Handle Minecraft handling. Ah...
        while (Keyboard.next()) {
            Logger.info("handleNumKey()", "The cake is a lie!");
        }
    }


}
 
Example 12
Source File: ClientOverworldStage.java    From FEMultiplayer with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void beginStep() {
	super.beginStep();
	for (Entity e : entities) {
		e.beginStep();
	}
	MapAnimation.updateAll();
	if (onControl) {
		List<KeyboardEvent> keys = Game.getKeys();
		if (Keyboard.isKeyDown(Keyboard.KEY_UP) && repeatTimers[0] == 0) {
			context.onUp();
			repeatTimers[0] = 0.12f;
		}
		if (Keyboard.isKeyDown(Keyboard.KEY_DOWN) && repeatTimers[1] == 0) {
			context.onDown();
			repeatTimers[1] = 0.12f;
		}
		if (Keyboard.isKeyDown(Keyboard.KEY_LEFT) && repeatTimers[2] == 0) {
			context.onLeft();
			repeatTimers[2] = 0.12f;
		}
		if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT) && repeatTimers[3] == 0) {
			context.onRight();
			repeatTimers[3] = 0.12f;
		}
		for(KeyboardEvent ke : keys) {
			if(ke.state) {
				if(ke.key == Keyboard.KEY_Z) 
					context.onSelect();
				else if (ke.key == Keyboard.KEY_X)
					context.onCancel(); 
			}
		}
	}
	for(int i=0; i<repeatTimers.length; i++) {
		if(repeatTimers[i] > 0) {
			repeatTimers[i] -= Game.getDeltaSeconds();
			if(repeatTimers[i] < 0) repeatTimers[i] = 0;
		}
	}
	processAddStack();
	processRemoveStack();
}
 
Example 13
Source File: Example10_3.java    From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void keyPressed(int key, char c) {
	boolean changedAtten = false;
	
	switch(key) {
		case Keyboard.KEY_SPACE:
			drawColoredCyl = !drawColoredCyl;
			break;
		case Keyboard.KEY_O:
			lightAttenuation *= Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) ? 1.1f : 1.5f;
			changedAtten = true;
			break;
		case Keyboard.KEY_U:
			lightAttenuation /= Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) ? 1.1f : 1.5f;
			changedAtten = true;
			break;
		case Keyboard.KEY_Y:
			drawLight = !drawLight;
			break;
		case Keyboard.KEY_T:
			scaleCyl = !scaleCyl;
			break;
		case Keyboard.KEY_H:
			useRSquare = !useRSquare;
			if(useRSquare)
				System.out.println("Inverse Squared Attenuation");
			else
				System.out.println("Plain Inverse Attenuation");
			
			break;
		case Keyboard.KEY_B:
			lightTimer.togglePause();
			break;
	}
	
	if(lightAttenuation < 0.1f)
		lightAttenuation = 0.1f;
	
	if(changedAtten)
		System.out.println("Atten: " + lightAttenuation);
}
 
Example 14
Source File: DrawScreenEventHandler.java    From Fullscreen-Windowed-Minecraft with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private static boolean isCorrectKeyBinding()
{
    return ClientProxy.fullscreenKeyBinding != null && Keyboard.isKeyDown(ClientProxy.fullscreenKeyBinding.getKeyCode());
}
 
Example 15
Source File: MCInputManager.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean isKeyDown(Key key) {
	// TODO: Sync this withPriority server side for server-side events. Need a packet manager
	return Keyboard.isKeyDown(getNativeKeyCode(key));
}
 
Example 16
Source File: Example11_2.java    From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void keyPressed(int key, char c) {
	boolean changedShininess = false;
	boolean changedLightModel = false;
	
	switch(key) {
		case Keyboard.KEY_SPACE:
			drawColoredCyl = !drawColoredCyl;
			break;
		case Keyboard.KEY_O:
			materialParams.increment(!(Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)));
			changedShininess = true;
			break;
		case Keyboard.KEY_U:
			materialParams.decrement(!(Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)));
			changedShininess = true;
			break;
		case Keyboard.KEY_Y:
			drawLightSource = !drawLightSource;
			break;
		case Keyboard.KEY_T:
			scaleCyl = !scaleCyl;
			break;
		case Keyboard.KEY_B:
			lightTimer.togglePause();
			break;
		case Keyboard.KEY_G:
			drawDark = !drawDark;
			break;
		case Keyboard.KEY_H:
			if(Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
				if(lightModel.ordinal() % 2 != 0)
					lightModel = LightingModel.values()[(lightModel.ordinal() - 1) % LightingModel.values().length];
				else
					lightModel = LightingModel.values()[(lightModel.ordinal() + 1) % LightingModel.values().length];
			} else
				lightModel = LightingModel.values()[(lightModel.ordinal() + 2) % LightingModel.values().length];
			
			changedLightModel = true;
			break;
	}
	
	if(changedShininess)
		System.out.printf("Shiny: %f\n", materialParams.getSpecularValue());
	
	if(changedLightModel)
		System.out.printf("%s\n", lightModel);
}
 
Example 17
Source File: CellViewer.java    From ehacks-pro with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onTicks() {
    try {
        boolean newState = Keyboard.isKeyDown(OpenAE2ViewerKeybind.getKey());
        if (newState && !prevState) {
            prevState = newState;
            GuiScreen screen = Wrapper.INSTANCE.mc().currentScreen;
            ItemStack cell = null;
            if (screen instanceof GuiContainer) {
                try {
                    ScaledResolution get = new ScaledResolution(Wrapper.INSTANCE.mc(), Wrapper.INSTANCE.mc().displayWidth, Wrapper.INSTANCE.mc().displayHeight);
                    int mouseX = Mouse.getX() / get.getScaleFactor();
                    int mouseY = Mouse.getY() / get.getScaleFactor();
                    GuiContainer container = (GuiContainer) screen;
                    Method isMouseOverSlot = GuiContainer.class.getDeclaredMethod(Mappings.isMouseOverSlot, Slot.class, Integer.TYPE, Integer.TYPE);
                    isMouseOverSlot.setAccessible(true);
                    for (int i = 0; i < container.inventorySlots.inventorySlots.size(); i++) {
                        //noinspection JavaReflectionInvocation
                        if ((Boolean) isMouseOverSlot.invoke(container, container.inventorySlots.inventorySlots.get(i), mouseX, get.getScaledHeight() - mouseY)) {
                            cell = container.inventorySlots.inventorySlots.get(i) == null ? null : ((Slot) container.inventorySlots.inventorySlots.get(i)).getStack();
                        }
                    }
                } catch (Exception ex) {
                    InteropUtils.log("&cError", this);
                }
            }
            if (cell == null) {
                return;
            }
            if (!(Class.forName("appeng.items.storage.ItemBasicStorageCell").isInstance(cell.getItem()))) {
                InteropUtils.log("&cNot a cell", this);
                return;
            }
            NBTTagCompound tag = cell.stackTagCompound;
            if (tag == null) {
                InteropUtils.log("&cCell is empty (new)", this);
                return;
            }
            try {
                ArrayList<ItemStack> stacks = new ArrayList<>();
                int count = tag.getShort("it");
                for (int i = 0; i < count; i++) {
                    ItemStack stack = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("#" + i));
                    stack.stackSize = (int) tag.getCompoundTag("#" + i).getLong("Cnt");
                    if (stack.stackTagCompound == null) {
                        stack.stackTagCompound = new NBTTagCompound();
                        stack.stackTagCompound.setString("render-cellviewer", "ok");
                    }
                    stacks.add(stack);
                }
                Wrapper.INSTANCE.mc().displayGuiScreen(new CellViewerGui(new CellViewerContainer(stacks.toArray(new ItemStack[stacks.size()]), cell.getDisplayName())));
            } catch (Exception e) {
                InteropUtils.log("&cError", this);
            }
        }
        prevState = newState;
    } catch (Exception ignored) {

    }
}
 
Example 18
Source File: GuiCyberwareMenu.java    From Cyberware with MIT License 4 votes vote down vote up
@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException
{

	if (keyCode == Keyboard.KEY_ESCAPE)
	{
		if (editing)
		{
			this.editing = false;
		}
		else
		{
			close = true;
		}
	}
	else if (keyCode == Keyboard.KEY_LSHIFT || keyCode == Keyboard.KEY_RSHIFT)
	{
		
	}
	else if (keyCode == KeyBinds.menu.getKeyCode())
	{
		
	}
	else if (this.selectedPart != -1 && editing)
	{
		boolean shiftPressed = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
		assignHotkey(keyCode + (shiftPressed ? 900 : 0));
		/*for (int i = 0; i < mc.gameSettings.keyBindsHotbar.length; i++)
		{
			KeyBinding kb = mc.gameSettings.keyBindsHotbar[i];
			if (kb.getKeyCode() == keyCode)
			{
				ICyberwareUserData data = CyberwareAPI.getCapability(mc.thePlayer);
				
				if (HotkeyHelper.getHotkey(data.getActiveItems().get(selectedPart)) != i)
				{
					HotkeyHelper.removeHotkey(data, i);
					HotkeyHelper.assignHotkey(data, data.getActiveItems().get(selectedPart), i);
					CyberwarePacketHandler.INSTANCE.sendToServer(new SyncHotkeyPacket(selectedPart, i));
				}

				return;
			}
		}*/
	}
	
	hex.textboxKeyTyped(typedChar, keyCode);
	if (hex.getText().length() >= 12)
	{
		hex.setText(hex.getText().substring(6, 12));
	}
	if (hex.getText().length() > 6)
	{
		hex.setText(hex.getText().substring(0, 6));
	}
	hex.setText(hex.getText().replaceAll("[^0-9AaBbCcDdEeFf]", ""));
	if (hex.getText().length() == 6)
	{
		CyberwareAPI.setHUDColor(Integer.parseInt(hex.getText(), 16));
	}
}
 
Example 19
Source File: Config.java    From CraftingKeys with MIT License 4 votes vote down vote up
public static boolean isKeyLowerCenterPressed() {
    return Keyboard.isKeyDown(keyLowerCenter.getInt(retDefKey)) || isNumPadEnabled() && Keyboard.isKeyDown(80);
}
 
Example 20
Source File: Config.java    From CraftingKeys with MIT License 4 votes vote down vote up
public static boolean isKeyInteractPressed() {
    return Keyboard.isKeyDown(keyInteract.getInt(retDefKey));
}