Java Code Examples for org.lwjgl.input.Keyboard#getEventKeyState()
The following examples show how to use
org.lwjgl.input.Keyboard#getEventKeyState() .
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: PlayerListener.java From SkyblockAddons with MIT License | 6 votes |
/** * This method handles key presses while the player is in-game. * For handling of key presses while a GUI (e.g. chat, pause menu, F3) is open, * see {@link GuiScreenListener#onKeyInput(GuiScreenEvent.KeyboardInputEvent)} * * @param e the {@code KeyInputEvent} */ @SubscribeEvent(receiveCanceled = true) public void onKeyInput(InputEvent.KeyInputEvent e) { if (main.getOpenSettingsKey().isPressed()) { main.getUtils().setFadingIn(true); main.getRenderListener().setGuiToOpen(EnumUtils.GUIType.MAIN, 1, EnumUtils.GuiTab.MAIN); } else if (main.getOpenEditLocationsKey().isPressed()) { main.getUtils().setFadingIn(false); main.getRenderListener().setGuiToOpen(EnumUtils.GUIType.EDIT_LOCATIONS, 0, null); } else if (Keyboard.getEventKey() == DevUtils.DEV_KEY && Keyboard.getEventKeyState()) { // Copy Mob Data if (main.isDevMode()) { EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; List<Entity> entityList = Minecraft.getMinecraft().theWorld.loadedEntityList; DevUtils.copyMobData(player, entityList); } } }
Example 2
Source File: LwjglKeyInput.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void update() { if (!context.isRenderable()) return; Keyboard.poll(); while (Keyboard.next()){ int keyCode = Keyboard.getEventKey(); char keyChar = Keyboard.getEventCharacter(); boolean pressed = Keyboard.getEventKeyState(); boolean down = Keyboard.isRepeatEvent(); long time = Keyboard.getEventNanoseconds(); KeyInputEvent evt = new KeyInputEvent(keyCode, keyChar, pressed, down); evt.setTime(time); listener.onKeyEvent(evt); } }
Example 3
Source File: Game.java From FEMultiPlayer-V2 with GNU General Public License v3.0 | 6 votes |
/** * Gets the input. * * @return the input */ public static void getInput() { Keyboard.poll(); keys.clear(); while(Keyboard.next()) { KeyboardEvent ke = new KeyboardEvent(Keyboard.getEventKey(), Keyboard.getEventCharacter(), Keyboard.isRepeatEvent(), Keyboard.getEventKeyState(), KeyboardEvent.generateModifiers()); keys.add(ke); } Mouse.poll(); mouseEvents.clear(); while(Mouse.next()) { MouseEvent me = new MouseEvent( Mouse.getEventX(), Mouse.getEventY(), Mouse.getEventDWheel(), Mouse.getEventButton(), Mouse.getEventButtonState()); mouseEvents.add(me); } }
Example 4
Source File: Game.java From FEMultiplayer with GNU General Public License v3.0 | 6 votes |
public static void getInput() { Keyboard.poll(); keys.clear(); while(Keyboard.next()) { KeyboardEvent ke = new KeyboardEvent( Keyboard.getEventKey(), Keyboard.getEventCharacter(), Keyboard.isRepeatEvent(), Keyboard.getEventKeyState()); keys.add(ke); } Mouse.poll(); mouseEvents.clear(); while(Mouse.next()) { MouseEvent me = new MouseEvent( Mouse.getEventX(), Mouse.getEventY(), Mouse.getEventDWheel(), Mouse.getEventButton(), Mouse.getEventButtonState()); mouseEvents.add(me); } }
Example 5
Source File: LwjglKeyInput.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public void update() { if (!context.isRenderable()) return; Keyboard.poll(); while (Keyboard.next()){ int keyCode = Keyboard.getEventKey(); char keyChar = Keyboard.getEventCharacter(); boolean pressed = Keyboard.getEventKeyState(); boolean down = Keyboard.isRepeatEvent(); long time = Keyboard.getEventNanoseconds(); KeyInputEvent evt = new KeyInputEvent(keyCode, keyChar, pressed, down); evt.setTime(time); listener.onKeyEvent(evt); } }
Example 6
Source File: GuiCapture.java From OpenPeripheral-Addons with MIT License | 6 votes |
@Override public void handleKeyboardInput() { final int key = Keyboard.getEventKey(); if (key == Keyboard.KEY_ESCAPE) { this.mc.displayGuiScreen(null); this.mc.setIngameFocus(); } else { final boolean state = Keyboard.getEventKeyState(); if (state) { final char ch = sanitizeKeyChar(Keyboard.getEventCharacter()); final boolean isRepeat = Keyboard.isRepeatEvent(); new GlassesKeyDownEvent(guid, ch, key, isRepeat).sendToServer(); } else { new GlassesKeyUpEvent(guid, key).sendToServer(); } } // looks like twitch controls super.handleKeyboardInput(); }
Example 7
Source File: MacroCommand.java From ForgeHax with MIT License | 6 votes |
@SubscribeEvent public void onKeyboardEvent(InputEvent.KeyInputEvent event) { MACROS .stream() .filter(macro -> !macro.isAnonymous()) .filter(macro -> macro.getBind().isPressed()) .forEach(this::executeMacro); // execute anonymous macros if (Keyboard.getEventKeyState()) { // on press MACROS .stream() .filter(MacroEntry::isAnonymous) .filter(macro -> macro.getKey() == Keyboard.getEventKey()) .forEach(this::executeMacro); } }
Example 8
Source File: InputEventHandler.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
@SubscribeEvent public void onKeyInputEvent(InputEvent.KeyInputEvent event) { int keyCode = Keyboard.getEventKey(); boolean keyState = Keyboard.getEventKeyState(); this.onInputEvent(keyCode, keyState); }
Example 9
Source File: GuiContainerManager.java From NotEnoughItems with MIT License | 5 votes |
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 10
Source File: KeyboardInput.java From tribaltrouble with GNU General Public License v2.0 | 5 votes |
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 11
Source File: NEIClientEventHandler.java From NotEnoughItems with MIT License | 5 votes |
@SubscribeEvent public void onKeyTypedPost(KeyboardInputEvent.Post event) { GuiScreen gui = event.getGui(); if (gui instanceof GuiContainer) { char c = Keyboard.getEventCharacter(); int eventKey = Keyboard.getEventKey(); if (eventKey == 0 && c >= 32 || Keyboard.getEventKeyState()) { if (eventKey != 1) { for (IInputHandler inputhander : inputHandlers) { if (inputhander.lastKeyTyped(gui, c, eventKey)) { event.setCanceled(true); return; } } } if (KeyBindings.get("nei.options.keys.gui.enchant").isActiveAndMatches(eventKey) && canPerformAction("enchant")) { NEIClientPacketHandler.sendOpenEnchantmentWindow(); event.setCanceled(true); } if (KeyBindings.get("nei.options.keys.gui.potion").isActiveAndMatches(eventKey) && canPerformAction("potion")) { NEIClientPacketHandler.sendOpenPotionWindow(); event.setCanceled(true); } } } }
Example 12
Source File: MixinGuiScreen.java From Hyperium with GNU Lesser General Public License v3.0 | 5 votes |
/** * @author SiroQ * @reason Fix input bug (MC-2781) **/ @Overwrite public void handleKeyboardInput() throws IOException { char character = Keyboard.getEventCharacter(); if (Keyboard.getEventKey() == 0 && character >= 32 || Keyboard.getEventKeyState()) { keyTyped(character, Keyboard.getEventKey()); } mc.dispatchKeypresses(); }
Example 13
Source File: InputEventHandler.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
@SubscribeEvent public void onGuiKeyInputEventPre(GuiScreenEvent.KeyboardInputEvent.Pre event) { if (event.getGui() instanceof GuiHandyBag) { int key = Keyboard.getEventKey(); // Double-tap shift if (Keyboard.getEventKeyState() && (key == Keyboard.KEY_LSHIFT || key == Keyboard.KEY_RSHIFT) && this.checkForDoubleTap(key)) { PacketHandler.INSTANCE.sendToServer(new MessageGuiAction(0, new BlockPos(0, 0, 0), ReferenceGuiIds.GUI_ID_HANDY_BAG, ItemHandyBag.GUI_ACTION_TOGGLE_SHIFTCLICK_DOUBLETAP, 0)); } } }
Example 14
Source File: GuiScreenListener.java From SkyblockAddons with MIT License | 5 votes |
/** * Listens for key presses while a GUI is open * * @param event the {@code GuiScreenEvent.KeyboardInputEvent} to listen for */ @SubscribeEvent() public void onKeyInput(GuiScreenEvent.KeyboardInputEvent event) { int eventKey = Keyboard.getEventKey(); if (eventKey == DevUtils.DEV_KEY && Keyboard.getEventKeyState()) { event.setCanceled(true); // Copy Item NBT if (main.isDevMode()) { GuiScreen currentScreen = event.gui; // Check if the player is in an inventory. if (GuiContainer.class.isAssignableFrom(currentScreen.getClass())) { Slot currentSlot = ((GuiContainer) currentScreen).getSlotUnderMouse(); if (currentSlot != null && currentSlot.getHasStack()) { DevUtils.copyNBTTagToClipboard(currentSlot.getStack().serializeNBT(), ChatFormatting.GREEN + "Item data was copied to clipboard!"); } } } } }
Example 15
Source File: HyperiumMinecraft.java From Hyperium with GNU Lesser General Public License v3.0 | 4 votes |
public void runTickKeyboard() { int key = Keyboard.getEventKey(); boolean repeat = Keyboard.isRepeatEvent(); boolean press = Keyboard.getEventKeyState(); EventBus.INSTANCE.post(press ? new KeyPressEvent(key, repeat) : new KeyReleaseEvent(key, repeat)); }
Example 16
Source File: GLProgram.java From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void gameLoop() { try { init(); Utils.checkGLError("init"); resized(); Utils.checkGLError("resized"); long lastTime, lastFPS; lastTime = lastFPS = System.nanoTime(); int frames = 0; while(!shouldStop()) { long deltaTime = System.nanoTime() - lastTime; lastTime += deltaTime; if(Display.wasResized()) resized(); while(Keyboard.next()) { if(Keyboard.getEventKeyState()) keyPressed(Keyboard.getEventKey(), Keyboard.getEventCharacter()); else keyReleased(Keyboard.getEventKey(), Keyboard.getEventCharacter()); } update(deltaTime); Utils.checkGLError("update"); render(); Utils.checkGLError("render"); Display.update(); frames++; if(System.nanoTime() - lastFPS >= 1e9) { System.out.println("FPS: ".concat(String.valueOf(frames))); lastFPS += 1e9; frames = 0; } Display.sync(fps); } } catch(Throwable exc) { exc.printStackTrace(); } finally { destroy(); } }
Example 17
Source File: MixinMinecraft.java From Happy_MinecraftClient with GNU General Public License v3.0 | 4 votes |
@Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;dispatchKeypresses()V", shift = At.Shift.AFTER)) private void keyPress(CallbackInfo callbackInfo) { if(Keyboard.getEventKeyState() && currentScreen == null) EventManager.callEvent(new KeyEvent(Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() + 256 : Keyboard.getEventKey())); }
Example 18
Source File: OpenGL3_TheQuadTextured.java From ldparteditor with MIT License | 4 votes |
private void loopCycle() { // Logic while(Keyboard.next()) { // Only listen to events where the key was pressed (down event) if (!Keyboard.getEventKeyState()) continue; // Switch textures depending on the key released switch (Keyboard.getEventKey()) { case Keyboard.KEY_1: textureSelector = 0; break; case Keyboard.KEY_2: textureSelector = 1; break; } } // Render GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); GL20.glUseProgram(pId); // Bind the texture GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texIds[textureSelector]); // Bind to the VAO that has all the information about the vertices GL30.glBindVertexArray(vaoId); GL20.glEnableVertexAttribArray(0); GL20.glEnableVertexAttribArray(1); GL20.glEnableVertexAttribArray(2); // Bind to the index VBO that has all the information about the order of the vertices GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId); // Draw the vertices GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_BYTE, 0); // Put everything back to default (deselect) GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); GL20.glDisableVertexAttribArray(0); GL20.glDisableVertexAttribArray(1); GL20.glDisableVertexAttribArray(2); GL30.glBindVertexArray(0); GL20.glUseProgram(0); this.exitOnGLError("loopCycle"); }
Example 19
Source File: MixinMinecraft.java From LiquidBounce with GNU General Public License v3.0 | 4 votes |
@Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;dispatchKeypresses()V", shift = At.Shift.AFTER)) private void onKey(CallbackInfo callbackInfo) { if(Keyboard.getEventKeyState() && currentScreen == null) LiquidBounce.eventManager.callEvent(new KeyEvent(Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() + 256 : Keyboard.getEventKey())); }
Example 20
Source File: MixinMinecraft.java From LiquidBounce with GNU General Public License v3.0 | 4 votes |
@Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;dispatchKeypresses()V", shift = At.Shift.AFTER)) private void onKey(CallbackInfo callbackInfo) { if(Keyboard.getEventKeyState() && currentScreen == null) LiquidBounce.eventManager.callEvent(new KeyEvent(Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() + 256 : Keyboard.getEventKey())); }