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

The following examples show how to use org.lwjgl.input.Keyboard#getEventKey() . 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: Game.java    From FEMultiplayer with GNU General Public License v3.0 6 votes vote down vote up
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 2
Source File: PlayerListener.java    From SkyblockAddons with MIT License 6 votes vote down vote up
/**
 * 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 3
Source File: GuiCapture.java    From OpenPeripheral-Addons with MIT License 6 votes vote down vote up
@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 4
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 5
Source File: LwjglKeyInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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 6
Source File: ShulkerViewer.java    From ForgeHax with MIT License 6 votes vote down vote up
@SubscribeEvent
public void onKeyboardInput(GuiScreenEvent.KeyboardInputEvent event) {
  if (Keyboard.getEventKey() == lockDownKey.getKeyCode()) {
    if (Keyboard.getEventKeyState()) {
      if (toggle_lock.get()) {
        if (!isKeySet) {
          locked = !locked;
          if (!locked) {
            updated = false;
          }
          isKeySet = true;
        }
      } else {
        locked = true;
      }
    } else {
      if (toggle_lock.get()) {
        isKeySet = false;
      } else {
        locked = updated = false;
      }
    }
  }
}
 
Example 7
Source File: Game.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 8
Source File: ClientProxy.java    From IGW-mod with GNU General Public License v2.0 5 votes vote down vote up
@SubscribeEvent
public void onGuiKeyBind(GuiScreenEvent.KeyboardInputEvent.Post event){
    char chr = Keyboard.getEventCharacter();
    int key = Keyboard.getEventKey();

    if(((key == 0 && chr >= 32) || Keyboard.getEventKeyState()) && key == openInterfaceKey.getKeyCode()) {
        handleSlotPresses();
    }
}
 
Example 9
Source File: InputEventHandler.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 10
Source File: InputEventHandler.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onKeyInputEvent(InputEvent.KeyInputEvent event)
{
    int keyCode = Keyboard.getEventKey();
    boolean keyState = Keyboard.getEventKeyState();

    this.onInputEvent(keyCode, keyState);
}
 
Example 11
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 12
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 13
Source File: NEIClientEventHandler.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@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 14
Source File: TestUtils.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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 15
Source File: KeybindProcessor.java    From ForgeWurst with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onKeyInput(InputEvent.KeyInputEvent event)
{
	int keyCode = Keyboard.getEventKey();
	if(keyCode == 0 || !Keyboard.getEventKeyState())
		return;
	
	String commands = keybinds.getCommands(Keyboard.getKeyName(keyCode));
	if(commands == null)
		return;
	
	commands = commands.replace(";", "\u00a7").replace("\u00a7\u00a7", ";");
	for(String command : commands.split("\u00a7"))
	{
		command = command.trim();
		
		if(command.startsWith("."))
			cmdProcessor.runCommand(command.substring(1));
		else if(command.contains(" "))
			cmdProcessor.runCommand(command);
		else
		{
			Hack hack = hax.get(command);
			
			if(hack != null)
				hack.setEnabled(!hack.isEnabled());
			else
				cmdProcessor.runCommand(command);
		}
	}
}
 
Example 16
Source File: HotKeyHandler.java    From I18nUpdateMod with MIT License 5 votes vote down vote up
/**
 * 单独功能,快速重载语言文件
 *
 * @return 是否成功
 */
private boolean reloadLocalization() {
    if (keyCodeCheck(reportKey.getKeyCode()) && Keyboard.isKeyDown(mainKey.getKeyCode()) && Keyboard.getEventKey() == reloadKey.getKeyCode()) {
        Minecraft.getMinecraft().getLanguageManager().onResourceManagerReload(Minecraft.getMinecraft().getResourceManager());
        Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation("message.i18nmod.cmd_reload.success"));
        return true;
    }
    return false;
}
 
Example 17
Source File: MixinGuiScreen.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @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 18
Source File: MoCGUIEntityNamer.java    From mocreaturesdev with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void handleKeyboardInput()
{
    if (Keyboard.getEventKeyState())
    {
        if (Keyboard.getEventKey() == 28) // Handle Enter Key
        {
            updateName();
        }
    }
    super.handleKeyboardInput();
}
 
Example 19
Source File: OpenGL3_TheQuadTextured.java    From ldparteditor with MIT License 4 votes vote down vote up
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 20
Source File: HyperiumMinecraft.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
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));
}