org.lwjgl.input.Keyboard Java Examples

The following examples show how to use org.lwjgl.input.Keyboard. 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: CreativeGive.java    From ehacks-pro with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onTicks() {
    boolean newState = Keyboard.isKeyDown(GiveKeybind.getKey());
    if (newState && !prevState) {
        prevState = newState;
        int slotId = 36 + Wrapper.INSTANCE.player().inventory.currentItem;
        if (Statics.STATIC_ITEMSTACK == null) {
            return;
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
            for (int i = 9; i < 45; i++) {
                setCreative(Statics.STATIC_ITEMSTACK, i);
            }
        } else {
            setCreative(Statics.STATIC_ITEMSTACK, slotId);
        }
        InteropUtils.log("Set", this);
    }
    prevState = newState;
}
 
Example #2
Source File: HotKeyHandler.java    From I18nUpdateMod with MIT License 6 votes vote down vote up
@SubscribeEvent
public void onKeyPressNoGui(InputEvent.KeyInputEvent e) {
    // 最开始,检测是否启用国际化配置
    if (I18nConfig.internationalization.openI18n && !I18nUtils.isChinese()) {
        return;
    }

    // 接下来检测是否关闭键位
    if (I18nConfig.key.closedKey) {
        return;
    }

    // 取消重复显示
    if (showed) {
        if (keyCodeCheck(reloadKey.getKeyCode()) && !Keyboard.isKeyDown(reloadKey.getKeyCode())) {
            showed = false;
        }
        return;
    }
    showed = reloadLocalization();
}
 
Example #3
Source File: WidgetComboBox.java    From Signals with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onKey(char key, int keyCode){
    if(fixedOptions) return false;
    if(enabled && isFocused() && keyCode == Keyboard.KEY_TAB) {//Auto-complete
        List<String> applicableElements = getApplicableElements();
        if(applicableElements.size() > 0) {
            setText(applicableElements.get(0));
            listener.onKeyTyped(this);
            return true;
        } else {
            return super.onKey(key, keyCode);
        }
    } else {
        return super.onKey(key, keyCode);
    }
}
 
Example #4
Source File: LobbyChatBox.java    From FEMultiplayer with GNU General Public License v3.0 6 votes vote down vote up
public void beginStep() {
	List<MouseEvent> mouseEvents = Game.getMouseEvents();
	for(MouseEvent event : mouseEvents) {
		if(event.button == 0) {
			if(inBounds(event.x, Game.getWindowHeight()-event.y)) {
				hasFocus = true;
			} else {
				hasFocus = false;
			}
		}
	}
	super.beginStep();
	if(hasFocus) {
		List<KeyboardEvent> keys = Game.getKeys();
		for(KeyboardEvent ke : keys) {
			if(ke.state) {
				if(ke.key == Keyboard.KEY_RETURN) { 
					send();
				}
			}
		}
	}
}
 
Example #5
Source File: ComplexOpsuState.java    From opsu-dance with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void keyPressed(KeyEvent e)
{
	for (OverlayOpsuState overlay : overlays) {
		overlay.keyPressed(e);
		if (e.isConsumed()) {
			return;
		}
	}
	if (focusedComponent != null) {
		if (e.keyCode == Keyboard.KEY_ESCAPE) {
			focusedComponent.setFocused(false);
			focusedComponent = null;
		} else {
			focusedComponent.keyPressed(e);
		}
		e.consume();
	}
}
 
Example #6
Source File: Example10_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) {
	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 #7
Source File: SimpleWindow.java    From ehacks-pro with GNU General Public License v3.0 6 votes vote down vote up
public void windowDragged(int x, int y) {
    if (!dragging) {
        return;
    }
    this.xPos = this.prevXPos + (x - this.dragX);
    this.yPos = this.prevYPos + (y - this.dragY);
    ScaledResolution res = new ScaledResolution(Wrapper.INSTANCE.mc(), Wrapper.INSTANCE.mc().displayWidth, Wrapper.INSTANCE.mc().displayHeight);
    if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
        if (this.xPos < 20) {
            this.xPos = 2;
        }
        if (this.yPos < 20) {
            this.yPos = 2;
        }
        if (this.xPos + this.width > res.getScaledWidth() - 20) {
            this.xPos = res.getScaledWidth() - this.width - 2;
        }
        if (this.yPos + this.height > res.getScaledHeight() - 20) {
            this.yPos = res.getScaledHeight() - this.height - 2;
        }
    }
}
 
Example #8
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 #9
Source File: GuiReactorControlRod.java    From BigReactors with MIT License 6 votes vote down vote up
@Override
protected void keyTyped(char inputChar, int keyCode) {
       if (keyCode == Keyboard.KEY_ESCAPE ||
       		(!this.rodName.isFocused() && keyCode == this.mc.gameSettings.keyBindInventory.getKeyCode())) {
           this.mc.thePlayer.closeScreen();
       }

	this.rodName.textboxKeyTyped(inputChar, keyCode);
	
	if(keyCode == Keyboard.KEY_TAB) {
		// Tab
		if(this.rodName.isFocused()) {
			this.rodName.setFocused(false);
		}
		else {
			this.rodName.setFocused(true);
		}
	}
	
	if(keyCode == Keyboard.KEY_RETURN) {
		// Return/enter
		this.actionPerformed((GuiButton)this.buttonList.get(2));
	}
}
 
Example #10
Source File: ItemFairyBell.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
@SideOnly(Side.CLIENT)
public static void onScroll(MouseEvent event) {
	EntityPlayer player = Minecraft.getMinecraft().player;
	if (player == null) return;

	if (Keyboard.isCreated() && event.getDwheel() != 0) {

		for (EnumHand hand : EnumHand.values()) {
			ItemStack stack = player.getHeldItem(hand);

			if (stack.getItem() != ModItems.FAIRY_BELL)
				continue;


			IMiscCapability cap = MiscCapabilityProvider.getCap(Minecraft.getMinecraft().player);
			if (cap == null) continue;

			cap.setSelectedFairy(null);

			PacketHandler.NETWORK.sendToServer(new PacketUpdateMiscCapToServer(cap.serializeNBT()));
		}
	}
}
 
Example #11
Source File: FEResources.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the key mapped name.
 *
 * @param internalKeyName the internal key name
 * @return the key mapped name
 */
public static String getKeyMappedName(String internalKeyName){
	if(internalKeyName.toUpperCase().equals("ENTER")){
		internalKeyName = "RETURN";
	}
	int key = Keyboard.getKeyIndex(internalKeyName.toUpperCase());
	int mappedKey = getKeyMapped(key);
	String mappedName = Keyboard.getKeyName(mappedKey);
	//this might seem redundant, but it's to allow code using the string "Enter" to map to the key "Return"
	//which then maps the key according to the bindings (possibly to something else)
	//if it's still "return" we want this translated back to "enter"
	if(mappedName.equals("RETURN")){
		return "ENTER";
	}
	return mappedName;
}
 
Example #12
Source File: HotKeyHandler.java    From I18nUpdateMod with MIT License 6 votes vote down vote up
/**
 * 获取输入按键,进行不同处理
 *
 * @param stack 物品
 * @return 是否成功
 */
private boolean handleKey(ItemStack stack) {
    if (stack != null && stack != ItemStack.EMPTY && stack.getItem() != Items.AIR) {
        // 问题报告界面的打开
        if (keyCodeCheck(reportKey.getKeyCode()) && Keyboard.isKeyDown(mainKey.getKeyCode()) && Keyboard.getEventKey() == reportKey.getKeyCode()) {
            return openReport(stack);
        }
        // Weblate 翻译界面的打开
        else if (keyCodeCheck(weblateKey.getKeyCode()) && Keyboard.isKeyDown(mainKey.getKeyCode()) && Keyboard.getEventKey() == weblateKey.getKeyCode()) {
            return openWeblate(stack);
        }
        // mcmod 百科界面的打开
        else if (keyCodeCheck(mcmodKey.getKeyCode()) && Keyboard.isKeyDown(mainKey.getKeyCode()) && Keyboard.getEventKey() == mcmodKey.getKeyCode()) {
            return openMcmod(stack);
        }
    }
    return false;
}
 
Example #13
Source File: KeybindButton.java    From ClientBase with MIT License 6 votes vote down vote up
@Override
public boolean keyPressed(int key, char c) {
    if (listening) {
        listening = false;

        if (Keyboard.getEventKey() != 256 && Keyboard.getEventCharacter() != 0) {
            int newValue = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() + 256 : Keyboard.getEventKey();


            if (listener != null)
                if (listener.onValueChange(newValue))
                    this.value = newValue;
        }

        updateState();
    }

    return super.keyPressed(key, c);
}
 
Example #14
Source File: LwjglRasteriser.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean isKeyDown(final int vkKey)
{
	if (!keyCodeMap.containsKey(vkKey))
		throw new RuntimeException("No mapping for :"+vkKey);
	
	Integer lwjglKey = keyCodeMap.get(vkKey);
	return Keyboard.isKeyDown(lwjglKey);
}
 
Example #15
Source File: GuiContainerManager.java    From NotEnoughItems with MIT License 5 votes vote down vote up
public void handleKeyboardInput() {
    // Support for LWGJL 2.9.0 or later
    int k = Keyboard.getEventKey();
    char c = Keyboard.getEventCharacter();
    if (Keyboard.getEventKeyState() || (k == 0 && Character.isDefined(c)))
        keyTyped(c, k);

    window.mc.dispatchKeypresses();
}
 
Example #16
Source File: MagicGive.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;
        createSpell();
    }
    prevState = newState;
}
 
Example #17
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 #18
Source File: MwGui.java    From mapwriter with MIT License 5 votes vote down vote up
public void exitGui() {
	//MwUtil.log("closing GUI");
	// set the mini map dimension to the GUI map dimension when closing
	this.mw.miniMap.view.setDimension(this.mapView.getDimension());
	this.mapMode.close();
	Keyboard.enableRepeatEvents(false);
	this.mc.displayGuiScreen((GuiScreen) null);
    this.mc.setIngameFocus();
    this.mc.getSoundHandler().resumeSounds();
}
 
Example #19
Source File: KeyboardInput.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public final void doCheckMagicKeys() {
	Deterministic deterministic = LocalEventQueue.getQueue().getDeterministic();
	if (deterministic.isPlayback()) {
		Keyboard.poll();
		while (Keyboard.next()) {
			int event_key = Keyboard.getEventKey();
			boolean event_key_state = Keyboard.getEventKeyState();
			checkMagicKey(deterministic, event_key_state, event_key, true, Keyboard.isRepeatEvent());
		}
	}
}
 
Example #20
Source File: ArrowButton.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_SPACE:
		case Keyboard.KEY_RETURN:
			mousePressedAll(LocalInput.LEFT_BUTTON, 0, 0);
			break;
	}
}
 
Example #21
Source File: VerticalGui.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(Keyboard.KEY_Y);
    if (newState && !prevState) {
        openGui();
    }
    prevState = newState;
}
 
Example #22
Source File: MacroModule.java    From seppuku with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void keyPress(EventKeyPress event) {
    for(Macro macro : Seppuku.INSTANCE.getMacroManager().getMacroList()) {
        if(event.getKey() == Keyboard.getKeyIndex(macro.getKey()) && Keyboard.getKeyIndex(macro.getKey()) != Keyboard.KEY_NONE) {
            final String[] split = macro.getMacro().split(";");

            for(String s : split) {
                Minecraft.getMinecraft().player.sendChatMessage(s);
            }
        }
    }
}
 
Example #23
Source File: Variables.java    From The-5zig-Mod with MIT License 5 votes vote down vote up
@Override
public void dispatchKeypresses() {
	int eventKey = org.lwjgl.input.Keyboard.getEventKey();
	int currentcode = eventKey == 0 ? org.lwjgl.input.Keyboard.getEventCharacter() : eventKey;
	if ((currentcode == 0) || (org.lwjgl.input.Keyboard.isRepeatEvent()))
		return;

	if (org.lwjgl.input.Keyboard.getEventKeyState()) {
		int keyCode = currentcode + (eventKey == 0 ? 256 : 0);
		MinecraftFactory.getClassProxyCallback().fireKeyPressEvent(keyCode);
	}
}
 
Example #24
Source File: CommandsModule.java    From seppuku with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void keyPress(EventKeyPress event) {
    if(this.prefix.getValue().length() == 1) {
        final char key = Keyboard.getEventCharacter();
        if(this.prefix.getValue().charAt(0) == key) {
            Minecraft.getMinecraft().displayGuiScreen(new GuiChat());
        }
    }
}
 
Example #25
Source File: MCInputManager.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void mapKeys() {
	// Map jlwgl input to NOVA Keys, slightly hacky but functional.
	for (Key key : Key.values()) {
		try {
			keys.put(Keyboard.class.getDeclaredField(key.name()).getInt(null), key);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
 
Example #26
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 #27
Source File: GuiWiki.java    From IGW-mod with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called when the screen is unloaded. Used to disable keyboard repeat events
 */
@Override
public void onGuiClosed(){
    super.onGuiClosed();
    Keyboard.enableRepeatEvents(false);
    mc.gameSettings.guiScale = oldGuiScale;
}
 
Example #28
Source File: SearchUpgradeHandler.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
public void render2D(float partialTicks, boolean helmetEnabled){
    ItemStack searchStack = ItemPneumaticArmor.getSearchedStack(FMLClientHandler.instance().getClient().thePlayer.getCurrentArmor(3));
    List<String> textList = new ArrayList<String>();
    if(searchStack == null) {
        textList.add("press '" + Keyboard.getKeyName(KeyHandler.getInstance().keybindOpenOptions.getKeyCode()) + "' to configure");
    } else {
        textList.add(searchStack.getDisplayName() + " (" + totalSearchedItemCount + " found)");
    }
    searchInfo.setText(textList);
}
 
Example #29
Source File: ComponentGui.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
protected void keyTyped(char typedChar, int keyCode) {
	// no super call!
	if (keyCode == Keyboard.KEY_ESCAPE) {
		this.mc.player.closeScreen();
	} else {
		root.keyTyped(typedChar, keyCode);
	}
}
 
Example #30
Source File: Test.java    From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void update(long deltaTime) {
	final float delta = deltaTime / (float)1e9;
	
	float turnSpeed = (float)Math.PI * delta;
	float moveSpeed = (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) ? 100 : 50) * delta;
	
	if(Mouse.isGrabbed()) {
		angle += turnSpeed * Mouse.getDX() / 20f;
		angleY -= turnSpeed * Mouse.getDY() / 20f;
	}
	
	if(Keyboard.isKeyDown(Keyboard.KEY_A))
		position.add((float)Math.cos(angle + Math.PI) * moveSpeed, 0, (float)Math.sin(angle + Math.PI) * moveSpeed);
	if(Keyboard.isKeyDown(Keyboard.KEY_D))
		position.sub((float)Math.cos(angle + Math.PI) * moveSpeed, 0, (float)Math.sin(angle + Math.PI) * moveSpeed);
	
	if(Keyboard.isKeyDown(Keyboard.KEY_W))
		position.sub((float)Math.cos(angle + Math.PI / 2) * moveSpeed, 0, (float)Math.sin(angle + Math.PI / 2) * moveSpeed);
	if(Keyboard.isKeyDown(Keyboard.KEY_S))
		position.add((float)Math.cos(angle + Math.PI / 2) * moveSpeed, 0, (float)Math.sin(angle + Math.PI / 2) * moveSpeed);
	
	if(Keyboard.isKeyDown(Keyboard.KEY_R))
		position.reset();
	
	if(Keyboard.isKeyDown(Keyboard.KEY_SPACE) && position.y() == 0)
		vy = 30;
	
	vy += gravity * delta;
	position.add(0, vy * delta, 0);
	
	if(position.y() < 0) {
		position.y(0);
		vy = 0;
	}
}