Java Code Examples for org.lwjgl.input.Keyboard#next()
The following examples show how to use
org.lwjgl.input.Keyboard#next() .
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: GuiScreenEditKeys.java From Hyperium with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void handleInput() throws IOException { if (listeningForNewKey) { if (Mouse.next()) { int button = Mouse.getEventButton(); if (Mouse.isButtonDown(button)) { selected.getKey().setKey(button - 100); listeningForNewKey = false; changeKey.displayString = "Change key"; return; } } if (Keyboard.next()) { int key = Keyboard.getEventKey(); if (Keyboard.isKeyDown(key)) { selected.getKey().setKey(key); listeningForNewKey = false; changeKey.displayString = "Change key"; return; } } } super.handleInput(); }
Example 2
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 3
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 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: LwjglKeyboardHandleModule.java From tprogers2048game with GNU General Public License v3.0 | 5 votes |
/** * Считывание последних данных из стека событий */ @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 7
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 8
Source File: GuiScreenPlus.java From Chisel with GNU General Public License v2.0 | 5 votes |
@Override public void handleInput() { while(Mouse.next()) { this.handleMouseInput(); } while(Keyboard.next()) { this.handleKeyboardInput(); } }
Example 9
Source File: TestUtils.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Game loop update */ public void update() { while (Keyboard.next()) { if (Keyboard.getEventKeyState()) { if (Keyboard.getEventKey() == Keyboard.KEY_Q) { // play as a one off sound effect oggEffect.playAsSoundEffect(1.0f, 1.0f, false); } if (Keyboard.getEventKey() == Keyboard.KEY_W) { // replace the music thats curretly playing with // the ogg oggStream.playAsMusic(1.0f, 1.0f, true); } if (Keyboard.getEventKey() == Keyboard.KEY_E) { // replace the music thats curretly playing with // the mod modStream.playAsMusic(1.0f, 1.0f, true); } if (Keyboard.getEventKey() == Keyboard.KEY_R) { // play as a one off sound effect aifEffect.playAsSoundEffect(1.0f, 1.0f, false); } if (Keyboard.getEventKey() == Keyboard.KEY_T) { // play as a one off sound effect wavEffect.playAsSoundEffect(1.0f, 1.0f, false); } } } // polling is required to allow streaming to get a chance to // queue buffers. SoundStore.get().poll(0); }
Example 10
Source File: ContainerManager.java From CraftingKeys with MIT License | 4 votes |
/** * 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 11
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 12
Source File: KeyboardInput.java From tribaltrouble with GNU General Public License v2.0 | 4 votes |
public final static void reset() { while (Keyboard.isCreated() && Keyboard.next()) ; }
Example 13
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(); } }