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

The following examples show how to use org.lwjgl.input.Keyboard#poll() . 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-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 2
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 3
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 4
Source File: LwjglKeyInput.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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 5
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 6
Source File: KeyboardInput.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public final boolean doPoll(GUIRoot gui_root) {
	Deterministic deterministic = LocalEventQueue.getQueue().getDeterministic();
	LocalInput local_input = LocalInput.getLocalInput();
	boolean result = false;
	Keyboard.poll();
	while (deterministic.log(Keyboard.next())) {
		result = true;
		int event_key = deterministic.log(Keyboard.getEventKey());
		boolean event_key_state = deterministic.log(Keyboard.getEventKeyState());
		char event_character = deterministic.log(Keyboard.getEventCharacter());
		boolean repeat_event = deterministic.log(Keyboard.isRepeatEvent());
		switch (event_key) {
			case Keyboard.KEY_LSHIFT:
			case Keyboard.KEY_RSHIFT:
				shift_down = event_key_state;
				break;
			case Keyboard.KEY_LCONTROL:
			case Keyboard.KEY_RCONTROL:
				control_down = event_key_state;
				break;
			case Keyboard.KEY_LMENU:
			case Keyboard.KEY_RMENU:
				menu_down = event_key_state;
				break;
		}
		if (checkMagicKey(deterministic, event_key_state, event_key, false, repeat_event))
			continue;
		if (event_key == Keyboard.KEY_NONE) {
			local_input.keyTyped(gui_root, event_key, event_character);
		} else if (event_key_state) {
			local_input.keyPressed(gui_root, event_key, event_character, shift_down, control_down, menu_down, repeat_event);
		} else {
			local_input.keyReleased(gui_root, event_key, event_character, shift_down, control_down, menu_down);
		}
	}
	return result;
}
 
Example 7
Source File: CustomKey.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void renderKey(int x, int y) {
    Keyboard.poll();
    boolean pressed = isButtonDown(key);
    String name = (type == 0) ? (mod.getSettings().isChroma() ? "------" : (ChatColor.STRIKETHROUGH.toString() + "------")) : getKeyOrMouseName(key);

    if (pressed != wasPressed) {
        wasPressed = pressed;
        lastPress = System.currentTimeMillis();
    }

    int textColor = getColor();
    int pressedColor = getPressedColor();
    int color;
    double textBrightness;

    if (pressed) {
        color = Math.min(255, (int) (mod.getSettings().getFadeTime() * 5.0 * (System.currentTimeMillis() - lastPress)));
        textBrightness = Math.max(0.0, 1.0 - (System.currentTimeMillis() - lastPress) / (mod.getSettings().getFadeTime() * 2.0));
    } else {
        color = Math.max(0, 255 - (int) (mod.getSettings().getFadeTime() * 5.0 * (System.currentTimeMillis() - lastPress)));
        textBrightness = Math.min(1.0, (System.currentTimeMillis() - lastPress) / (mod.getSettings().getFadeTime() * 2.0));
    }

    int left = x + xOffset;
    int top = y + yOffset;
    int right;
    int bottom;

    if (type == 0 || type == 1) {
        right = x + xOffset + 70;
        bottom = y + yOffset + 16;
    } else {
        right = x + xOffset + 22;
        bottom = y + yOffset + 22;
    }

    if (mod.getSettings().isKeyBackgroundEnabled()) {
        if (mod.getSettings().getKeyBackgroundRed() == 0 && mod.getSettings().getKeyBackgroundGreen() == 0 && mod.getSettings().getKeyBackgroundBlue() == 0) {
            Gui.drawRect(left, top, right, bottom,
                new Color(mod.getSettings().getKeyBackgroundRed(), mod.getSettings().getKeyBackgroundGreen(), mod.getSettings().getKeyBackgroundBlue(),
                    mod.getSettings().getKeyBackgroundOpacity()).getRGB() + (color << 16) + (color << 8) + color);
        } else {
            Gui.drawRect(left, top, right, bottom,
                new Color(mod.getSettings().getKeyBackgroundRed(), mod.getSettings().getKeyBackgroundGreen(), mod.getSettings().getKeyBackgroundBlue(),
                    mod.getSettings().getKeyBackgroundOpacity()).getRGB());
        }
    }

    hitbox.setLeft(left);
    hitbox.setTop(top);
    hitbox.setRight(right);
    hitbox.setBottom(bottom);

    int red = textColor >> 16 & 0xFF;
    int green = textColor >> 8 & 0xFF;
    int blue = textColor & 0xFF;
    int colorN = new Color(0, 0, 0).getRGB() + ((int) (red * textBrightness) << 16) + ((int) (green * textBrightness) << 8) + (int) (blue * textBrightness);
    final float yPos = y + yOffset + 8;
    final FontRenderer fontRendererObj = Minecraft.getMinecraft().fontRendererObj;
    if (mod.getSettings().isChroma()) {
        if (type == 0) {
            int xIn = x + (xOffset + 76) / 4;
            int y2 = y + yOffset + 9;
            GlStateManager.pushMatrix();
            GlStateManager.translate((float) xIn, (float) y2, 0.0f);
            GlStateManager.rotate(-90.0f, 0.0f, 0.0f, 1.0f);
            drawGradientRect(0, 0, 2, 35, Color.HSBtoRGB((System.currentTimeMillis() - xIn * 10 - y2 * 10) %
                2000L / 2000.0f, 0.8f, 0.8f), Color.HSBtoRGB((System.currentTimeMillis() - (xIn + 35) * 10 - y2 * 10) %
                2000L / 2000.0f, 0.8f, 0.8f));
            GlStateManager.popMatrix();
        } else if (type == 1) {
            drawChromaString(name, x + ((xOffset + 70) / 2) - fontRendererObj.getStringWidth(name) / 2, y + yOffset + 5, 1.0F);
        } else {
            drawChromaString(name, (left + right) / 2 - fontRendererObj.getStringWidth(name) / 2, (int) yPos, 1.0);
        }
    } else if (type == 0 || type == 1) {
        drawCenteredString(name, x + (xOffset + 70) / 2, y + yOffset + 5, pressed ? pressedColor : colorN);
    } else {
        mc.fontRendererObj.drawString(name, (left + right) / 2 - fontRendererObj.getStringWidth(name) / 2, (int) yPos, pressed ? pressedColor : colorN);
    }
}
 
Example 8
Source File: SpaceKey.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void renderKey(int x, int y) {
    int yOffset = this.yOffset;

    if (!mod.getSettings().isShowingMouseButtons()) yOffset -= 24;
    if (!mod.getSettings().isShowingSneak()) yOffset -= 18;
    if (!mod.getSettings().isShowingWASD()) yOffset -= 48;

    Keyboard.poll();
    boolean pressed = isButtonDown(key.getKeyCode());
    String name = this.name.equalsIgnoreCase("space") ? (mod.getSettings().isChroma() ? "------" : (ChatColor.STRIKETHROUGH.toString() + "------")) : "Sneak";

    if (pressed != wasPressed) {
        wasPressed = pressed;
        lastPress = System.currentTimeMillis();
    }

    int textColor = getColor();
    int pressedColor = getPressedColor();

    double textBrightness;
    int color;

    if (pressed) {
        color = Math.min(255, (int) ((mod.getSettings().getFadeTime() * 5) * (System.currentTimeMillis() - lastPress)));
        textBrightness = Math.max(0.0D, 1.0D - (double) (System.currentTimeMillis() - lastPress) / (mod.getSettings().getFadeTime() * 2));
    } else {
        color = Math.max(0, 255 - (int) ((mod.getSettings().getFadeTime() * 5) * (System.currentTimeMillis() - lastPress)));
        textBrightness = Math.min(1.0D, (double) (System.currentTimeMillis() - lastPress) / (mod.getSettings().getFadeTime() * 2));
    }

    if (mod.getSettings().isKeyBackgroundEnabled()) {
        if (mod.getSettings().getKeyBackgroundRed() == 0 && mod.getSettings().getKeyBackgroundGreen() == 0 && mod.getSettings().getKeyBackgroundBlue() == 0) {
            Gui.drawRect(x + xOffset, y + yOffset, x + xOffset + 70, y + yOffset + 16,
                new Color(mod.getSettings().getKeyBackgroundRed(), mod.getSettings().getKeyBackgroundGreen(), mod.getSettings().getKeyBackgroundBlue(),
                    mod.getSettings().getKeyBackgroundOpacity()).getRGB() + (color << 16) + (color << 8) + color);
        } else {
            Gui.drawRect(x + xOffset, y + yOffset, x + xOffset + 70, y + yOffset + 16,
                new Color(mod.getSettings().getKeyBackgroundRed(), mod.getSettings().getKeyBackgroundGreen(), mod.getSettings().getKeyBackgroundBlue(),
                    mod.getSettings().getKeyBackgroundOpacity()).getRGB());
        }
    }

    int red = textColor >> 16 & 255;
    int green = textColor >> 8 & 255;
    int blue = textColor & 255;

    int colorN = new Color(0, 0, 0).getRGB() + ((int) ((double) red * textBrightness) << 16) + ((int) ((double) green * textBrightness) << 8)
        + (int) ((double) blue * textBrightness);

    if (mod.getSettings().isChroma()) {
        if (this.name.equalsIgnoreCase("space")) {
            int xIn = x + (xOffset + 76) / 4;
            int y2 = y + yOffset + 9;
            GlStateManager.pushMatrix();
            GlStateManager.translate((float) xIn, (float) y2, 0.0f);
            GlStateManager.rotate(-90.0f, 0.0f, 0.0f, 1.0f);
            drawGradientRect(0, 0, 2, 35, Color.HSBtoRGB((float) ((System.currentTimeMillis() - xIn * 10 - y2 * 10) % 2000L) / 2000.0f,
                0.8f, 0.8f), Color.HSBtoRGB((float) ((System.currentTimeMillis() - (xIn + 35) * 10 - y2 * 10) % 2000L) / 2000.0f,
                0.8f, 0.8f));
            GlStateManager.popMatrix();
        } else {
            drawChromaString(name, x + ((xOffset + 70) / 2) - Minecraft.getMinecraft().fontRendererObj.getStringWidth(name) / 2, y + yOffset + 5, 1.0F);
        }
    } else {
        drawCenteredString(name, x + (xOffset + 70) / 2, y + yOffset + 5, pressed ? pressedColor : colorN);
    }
}